hmm..i'm doing something like a simple registration.. the user will input the information being asked, then those info will be stored into an array..are spaces not allowed to be stored in an array..?

well, i can't explain the problem that much.. here's my simple code:

#include <stdio.h>
int i;
char Lname[15],Fname[15],Mname[15],sex[2];

main()
{     
      printf("\n        Simple Registration System        \n");
      for (i=1;i<=80;i++)
          { printf("_"); }

      printf("Please provide all the information needed.");
      printf("\nLast Name: ");
         scanf("%s",&Lname);
      printf("\nFirst Name: ");
         scanf("%s",&Fname); 
      printf("\nMiddle Name: ");
         scanf("%s",&Mname); 
      printf("\nSex (M/F): ");
         scanf("%s",&sex);
      printf("\n\nWelcome Mr./Ms. %s %c. %s !",Fname,Mname[0],Lname);  



getch();      
}      

if the user's first name, for example is anna marie, the program won't be storing the second name into &Fname, instead, it'll be stored on &Mname...

Fname would now be holding anna, then &Mname will have marie as its value

Edited 4 Years Ago by hyung101

That's because scanf() stops reading at spaces. You'll have to use something like fgets() or a complex/convoluted format specifier in scanf().

oh, thank you for that.. can i ask for a sample code.. i would appreciate it so much.. thank you

This article has been dead for over six months. Start a new discussion instead.