Guys, I got a problem in File Handling..
I entered two words(My World)to be saved in a file
but the file displays the first word only.
Can you guys help me....

Can we see the code?

here's the code:


#include<stdio.h>
#include<conio.h>
{
FILE *fp;
char name[45];
fp=fopen("c:\\file.txt","a+");
clrscr();
gotoxy(33,3);cout<<"ADD ENTRY"<<endl;
do
{
fscanf(fp,"%s",&name);
}
while(!feof(fp));
printf("Enter Name:");
scanf("%s",&name);
fprintf(fp,"%s\n",name);
getch();
fclose(fp);
}

Try using fgets to read from stdin.

char *fgets(char *s, int size, FILE *stream)

%s only stores the string till its finds its first white space.so in case where u r using %s only the first word gets stored.
to store word with white spaces use gets and fgets

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.