fscanf,fgets,fread,fgetc

哪个可以用来读取names.txt文件中的名字并存储在charstr[100]10]中,本人想不到简单或者可行的办法?谢谢!names.txt"MARY","PATRIC... 哪个可以用来读取 names.txt 文件中的名字并存储在char str[100]10]中,本人想不到简单或者可行的办法?谢谢!
names.txt
"MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN","BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE","LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY","CYNTHIA","ANGELA","MELISSA","BRENDA","AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE","CAROLYN","CHRISTINE","MARIE","JANET","CATHERINE","FRANCES","ANN","JOYCE","DIANE","ALICE","JULIE","HEATHER","TERESA","DORIS","GLORIA","EVELYN","JEAN","CHERYL","MILDRED","KATHERINE","JOAN","ASHLEY","JUDITH","ROSE","JANICE","KELLY","NICOLE","JUDY","CHRISTINA","KATHY","THERESA","BEVERLY"
展开
 我来答
百度网友1fc36d4
2012-05-12 · TA获得超过3128个赞
知道大有可为答主
回答量:1497
采纳率:100%
帮助的人:1803万
展开全部
注意修改下names.txt的路径,我是在d盘下

#include <stdio.h>
#include <string.h>

int main()
{
FILE *fp;
char buf[20],c;
char str[100][10];
int count=0;
if((fp=fopen("d:\\names.txt","r"))==NULL)
{
printf("open names.txt failed");
getchar();
return -1;
}

while(1)
{
if(fscanf(fp,"%[^,]",buf)<=0) break;
buf[strlen(buf)-1]='\0';
strcpy(str[count],buf+1);
puts(str[count]);
count++;
if(fscanf(fp,"%c",&c)<=0) break;
}
fclose(fp);
getchar();
return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式