For the code below, My input’s are as following:
score Bob 10
score Jill 20
score Han 20
highscore
best Bob
code:
#include <stdio.h>
#include <string.h>
typedef struct score_entry
{
char name[21];
int score;
} score_entry;
int main(void) {
int i;
char s[100];
score_entry readin[30];
while (1 == scanf("%s",(char*)s))
{
if (strncmp(s,"score",5)){
//how to store string an name ?
i++;
}
}
return 0;
}
The string s after the if statement is “nameint” … I want to store the name to readin[i].name and the int to readin[i].score … How exactly can i do that ?
EDIT
This works: