// test2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
typedef struct IDTAG {
char name[9];
char id[10];
} ID_STRUCT;
ID_struct idlist[44];
int sub(int *&ptr)
{
ptr[1] = 1;
return 1;
}
int main(int argc, char* argv[])
{
FILE * pf;
int i, j, bFound;
char str[255], name[12], id[10];
pf = fopen("D:\\CDLiou\\ds\\Cpp Ex\\test2\\NameList.txt", "r");
if (!pf)
return;
i = 0;
while (!feof(pf)) {
fgets(str, sizeof(str), pf);
sscanf(str, "%s %s", id, name);
strcpy(idlist[i].id, id);
strcpy(idlist[i].name, name);
printf("%d:%s\n", i, id);
++i;
}
fclose(pf);
//getch();
printf("Please enter name : ");
scanf("%s", str);
bFound = 0;
for (j=0; j<i; ++j) {
if (strcmp(idlist[j].name, str) == 0) {
bFound = 1;
break;
}
}
if (bFound) {
printf ("\nFound the name %s, id = %s\n", idlist[j].name, idlist[j].id);
}
getch();
//return 0;
}
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
==> 在 sushovah@cis_nctu (哀 唸不完啦) 的文章中提到: