Hi, im pretty new to C
im trying to make a program that will read a input.dat file
John Smith
Ben Some
Jeff More
and output it to output.dat file but
Smith John
Some Ben
Jeff More
using sequential file
Thank you
Hi, im pretty new to C
im trying to make a program that will read a input.dat file
John Smith
Ben Some
Jeff More
and output it to output.dat file but
Smith John
Some Ben
Jeff More
using sequential file
Thank you
well i can do that but when i use fgetc
but im pretty sure im suppose to use fgets for that
ok i've heard of scanf but whats sscanf
and one more thing please
how do i exchange the First name and last name
John Smith
to
Smith John
once i assigned the values to variables how do i output it
#include <stdio.h>
#include <stdlib.h>
FILE *fp, *out;
main()
{
char FName;
char LName;
char ch;
if((fp = fopen("client.dat","r")) == NULL)
{
printf("\nNo file opened.");
exit(1);
}
if((out = fopen("output.dat", "w")) == NULL)
{
printf("\nNo output file opened.");
exit(1);
}
while fgets(ch, 0, fp) != EOF) (
scanf("%s", &FName);
scanf("%s", &LName);
fputs(&ch, out);
fclose(fp);
fclose(out);
}
Please use code tags when posting code.
Here is your original code, with some modifications.
Code:#include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp, *out; char FName[100]; char LName[100]; char line[100]; if ((fp = fopen("client.dat", "r")) == NULL) { printf("\nNo file opened.\n"); return (EXIT_FAILURE); } if ((out = fopen("output.dat", "w")) == NULL) { printf("\nNo output file opened."); return (EXIT_FAILURE); } while (fgets(line, sizeof(line), fp) != NULL) { sscanf(line, "%s%s", FName, LName); fprintf(out, "%s %s\n", LName, FName); } fclose(fp); fclose(out); return 0; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thanks alot