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.
I wish to enter the name on one line and the number on another line
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.txt","w");
for(x=1; x<=5; x++)
{
printf("Enter a name \n");
gets(name);
printf("Enter a mark \n");
scanf("%d",&mark);
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.txt","w");
while ( fscanf(f,”%s”,name )
{
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.
so if someone can help me that would be great.