Hello Friends,
This is my first post, I am new to programming, trying to learn unix c programming , i needed a help, I have a small program to write a simple data to a file which is created through fopen. the code is below :
-------------------------------------------------
#include<stdio. h>
#include<stdlib .h>
#include<string .h>
int main()
{
FILE *john;
char typo[1000];
john=fopen("/home/cpp/john.txt", "wt");
if(!john)
{
perror("Failed opening file john.txt for appending\n");
}
printf("enter your name\n");
fscanf(stdin, "%s", &typo);
fwrite(&typo, sizeof(typo) , 10, john);
fclose(john);
return 0;
}
-----------------------------------------------------------------
The program is getting compiled properly without any errors, even i run the executable file, it asks for my name and then i enter "my name is shaun" after that when i check the john.txt file, it shows all junk characters filled in the file, can anyone help me out with this.
This is my first post, I am new to programming, trying to learn unix c programming , i needed a help, I have a small program to write a simple data to a file which is created through fopen. the code is below :
-------------------------------------------------
#include<stdio. h>
#include<stdlib .h>
#include<string .h>
int main()
{
FILE *john;
char typo[1000];
john=fopen("/home/cpp/john.txt", "wt");
if(!john)
{
perror("Failed opening file john.txt for appending\n");
}
printf("enter your name\n");
fscanf(stdin, "%s", &typo);
fwrite(&typo, sizeof(typo) , 10, john);
fclose(john);
return 0;
}
-----------------------------------------------------------------
The program is getting compiled properly without any errors, even i run the executable file, it asks for my name and then i enter "my name is shaun" after that when i check the john.txt file, it shows all junk characters filled in the file, can anyone help me out with this.
Comment