Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
#include<stdio.h>
void main()
{

    char name[30];
    int i;

    printf("Enter ur name:\n");
    for(i=0;i<30;i++)
    scanf("%s",&name[i]);



    for(i=0;i<30;i++)
    printf("The name is :%s",name[i]);
}
Posted
Comments
cp-4711 15-Oct-14 10:46am    
I think You want to read 30 names?
But You have only space for one name in the length of 30

You're printf statement is using %s, which is for ASCIIZ strings and you are printing individual characters name[i] - which are being treated as pointers to a string in the "who knows where" of your O/S

either printf("%s", name);
or printf("%c", name[i]); // for your loop


 
Share this answer
 
C#
// wf-protection-fault-error.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>

const int max_namecount   =5;   // 5 names
const int max_namelength  =50;  // each name has space for 50 chars

int main(int argc, char *argv[]) 
{
    char name[max_namecount][max_namelength+3];
    int i;

    printf("Enter your name:\n");
    for(i=0;i<max_namecount;i++)  scanf("%50s",name[i]); // 50=max_namelength:  makes sure, that you do not read more chars than you have space in name

    getc(stdin); // only for pause
    for(i=0;i<max_namecount;i++)  printf("\nThe name is :%s",name[i]);

    getc(stdin); // only for pause
      return 0;
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900