TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ken H
NA
646
360.1k
How to get the field value is assigned to the variables of the structure in .txt file
Jun 27 2012 4:41 AM
hi all,
i have a file name for
StuInfo.txt
,It has the following content:
stuName stuNum stuProfession EnglishScore NatureScore
Ken 2003001 Soft-Eng 98.5 88.5
FoxH 2003002 Database-Eng 90 75.5
......
.cpp code:
#include<stdio.h>
#include <stdlib.h>
#include <iostream.h>
#define SIZE 20
struct Student_Score
{
char stuName[10];
int stuID;
char stuPro[10];
float EnglishScore;
float NatureScore;
}stu_info[SIZE];
int main(void)
{
FILE *fp;
int i;
char fname[128]="StuInfo.txt";
if((fp=fopen(fname, "r"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
for (i=0;i<SIZE;i++)
{
fread(&stu_info[i],sizeof(Student_Score),1,fp);
printf("%s\n",stu_info[i].stuName); //
now,I just want to get name. how do?
}
fclose(fp);
return 0;
}
thank very much.
Reply
Answers (
1
)
What does LayoutKind.Sequential mean?
String Separator