I read the faq's that vart suggested on fflush, feof, and fgets. I made the necessary changes I also am now reading in binary mode. the only effect now is that it is ony printing three characters from the string.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define size 2
struct clientInfo
{
char name[25];
char address[25];
char telNumber[25];
char attentionItem [25];
char problemDescription[6];
};
int main()
{
int i,ch;
struct clientInfo data[size];
struct clientInfo dat;
FILE *clientFile;
clientFile = fopen("clients.txt","wb");
for (i = 0; i < size; i++)
{
printf ("Please enter your name\n");
fgets (data[i].name,sizeof(sizeof(char) * 25),stdin);
//fflush(stdin);
while ((ch = getchar()) != '\n' && ch != EOF);
printf ("Please enter your address\n");
fgets (data[i].address,sizeof(sizeof(char) * 25),stdin);
//fflush(stdin);
while ((ch = getchar()) != '\n' && ch != EOF);
printf ("Please enter your telephone number\n");
fgets (data[i].telNumber,sizeof(sizeof(char) * 25),stdin);
//fflush(stdin);
while ((ch = getchar()) != '\n' && ch != EOF);
printf ("Please enter the item which aquires attention\n");
fgets (data[i].attentionItem,sizeof(sizeof(char) * 25),stdin);
while ((ch = getchar()) != '\n' && ch != EOF);
//fflush(stdin);
printf ("Please enter a description of the problem\n");
fgets (data[i].problemDescription,sizeof(sizeof(char) * 6),stdin);
while ((ch = getchar()) != '\n' && ch != EOF);
fwrite(&data[i],sizeof(data[i]),1,clientFile);
}//endfor
fclose(clientFile);
clientFile = fopen("clients.txt","rb");
while(fread(&dat,sizeof(struct clientInfo),1,clientFile) != 0)
{
printf("name is %s\n",dat.name);
printf("address is %s\n",dat.address);
printf("telephone is %s\n",dat.telNumber);
printf("attention is %s\n",dat.attentionItem);
printf("problem is %s\n",dat.problemDescription);
}//end while
fclose(clientFile);
system("pause");
return 0;
}//endmain
Why is it only printing three characters from each string
for example if I entered Michelle for a name it gives me "Mic" only
Thanks in advance