| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1037 人关注过本帖
标题:字符串对比问题,大神们帮忙查查错 谢谢了
取消只看楼主 加入收藏
yuanda199312
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2018-4-12
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:0 
字符串对比问题,大神们帮忙查查错 谢谢了
// 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里的字符串是否存在于结构体里面的字符串。。。为什么没显示啊。。。明明都存在的啊。
搜索更多相关主题的帖子: the int FILE dat and 
2018-05-17 07:56
快速回复:字符串对比问题,大神们帮忙查查错 谢谢了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.156209 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved