I am trying to answer a question with regards to entering a set of numbers and text, and then I have got to search for a number and the text with it.
This is the code that I have written for inputting the numbers:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int mark;
int x;
FILE *f;
f = fopen("black.tx t","w");
for(x=1; x<=5; x++)
{
printf("Enter a name \n");
gets(name);
printf("Enter a mark \n");
scanf("%d",&mar k);
fprintf(f,"%s %d\n",name, mark);
}
fclose(f);
return 0;
}
it will not input the number and mark correctly together
the other part of the code to display a certain number and text is :
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int number;
int x;
FILE *f;
f = fopen("black.tx t","w");
while ( fscanf(f,ā%sā,n ame )
{
if (number=10)
{
printf(ā%s \nā,name);
}
}
fclose(f);
return 0;
}
this part is not working properly either and I am unable to spot what is wrong with it. i think because i've been looking at it for a while i just cant see the problems
so if someone can help me that would be great
This is the code that I have written for inputting the numbers:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int mark;
int x;
FILE *f;
f = fopen("black.tx t","w");
for(x=1; x<=5; x++)
{
printf("Enter a name \n");
gets(name);
printf("Enter a mark \n");
scanf("%d",&mar k);
fprintf(f,"%s %d\n",name, mark);
}
fclose(f);
return 0;
}
it will not input the number and mark correctly together
the other part of the code to display a certain number and text is :
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main()
{
char name[20];
int number;
int x;
FILE *f;
f = fopen("black.tx t","w");
while ( fscanf(f,ā%sā,n ame )
{
if (number=10)
{
printf(ā%s \nā,name);
}
}
fclose(f);
return 0;
}
this part is not working properly either and I am unable to spot what is wrong with it. i think because i've been looking at it for a while i just cant see the problems
so if someone can help me that would be great
Comment