| re: cant find the problem with my text file
this part is not working properly either and I am unable to spot what is wrong with it.
so if someone can help me that would be great.[/quote]
Dude,
Here is the corrected code. Please go thro. I dont want to (too lazy to) tell where i did the changes.. you will find them anyways :)
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int mark;
int x;
FILE *f;
f = fopen("c:/black.txt","w");
for(x=1; x<=10; x++)
{
printf("Enter a name \n");
scanf("%s",name);
printf("Enter a mark \n");
scanf("%d",&mark);
fprintf(f,"%s %d\n",name, mark);
}
fclose(f);
return 0;
}
include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int number;
int x;
FILE *f;
f = fopen("c:/black.txt","r");
while ( fscanf(f,"%s %d",name,&number) != EOF )
{
if (number==10)
{
printf("%s \n",name);
}
}
fclose(f);
return 0;
}
Regards,
ShaggY@FtF
|