字符串对比问题,大神们帮忙查查错 谢谢了
// Assignment2.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include <string.h>
int main()
{
typedef struct
{
char TeamName[16];
char Group[2];
int GamesPlayed;
int GamesWon;
int GamesDrawn;
int GamesLost;
int GoalsFor;
int GoalAgainst;
int Points;
}team_t;
team_t record[32];
FILE *stream, *stream2; // variable name
char teamname[32][16];
char group[32][2];
char team1[16];
char team2[16];
int score1;
int score2;
int i=0;
errno_t err;
err = fopen_s(&stream, "C:\\Users\\User\\Desktop\\2018\\engg1003\\c3270010PI2\\c3270010PI2\\team.dat", "r"); //oprn the read file and check the file open or not
if (err == 0)
{
printf("The file team.dat was opened\n");
}
else
{
printf("The file team.dat wasn’t opened\n");
}
while (!feof(stream))
{
fscanf_s(stream, "%s %s", record[i].TeamName,16,record[i].Group,2); //scan and print the value of teamname and group from read file
printf_s("%s %s\n", record[i].TeamName, record[i].Group);
i++;
}
if (stream)
{
err = fclose(stream);
if (err == 0)
{
printf("The file team.dat was closed\n");
}
else
{
printf("The file team.dat wasn’t closed\n");
}
}
err = fopen_s(&stream2, "C:\\Users\\User\\Desktop\\2018\\engg1003\\c3270010PI2\\c3270010PI2\\match.dat", "r"); //oprn the read file and check the file open or not
if (err == 0)
{
printf("The file match.dat was opened\n");
}
else
{
printf("The file match.dat wasn’t opened\n");
}
while (!feof(stream2))
{
fscanf_s(stream2, "%s %d %s %d\n", team1, 16, &score1, team2, 16, &score2); //scan and print the value of teamname and group from read file
//printf_s("%s %d %s %d\n", team1, score1, team2, score2);
if (score1 < 0 || score2 < 0)
{
printf_s("%s %d %s %d is invaild\n", team1, score1, team2, score2);
};
if (strcmp(team1, record[i].TeamName) != 0)
{
printf_s("the name is not in teamlist\n");
i++;
}
}
当我查询team1里的字符串是否存在于结构体里面的字符串。。。为什么没显示啊。。。明明都存在的啊。