| | |
Need Help,plz...><
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2005
Posts: 4
Reputation:
Solved Threads: 0
ok,i'm suppose to read all the "CP0X"(where x is a number) from a file and save it into a array.Then read the name(the YYYYY,ZZZZZ,etc) and save each them into array.
Example:
CP01 YYYYY
CP02 ZZZZZ
CP04 WWWW
CP01 RRRRR
CP03 UUUUU
.
.
.
CPO2 TTTTT
So....i did this->
for(int i=0;i<10;i++)
{
infile.getline(rarray[i].module,4);
cout<<rarray[i].module;
}
where everything listed here are declared properly.It should by right show me something like CP01->rarray[0].module,CP02->rarray[1].module,CP04,CP01,CP03,where each "CP0X" is stored correctly in rarray[i].module.BUT it didn't.I want them reading the data downwards then saving the data correctly into the array,not overflowing into the next array for the name.Can someone please help me with this?Thanks
Example:
CP01 YYYYY
CP02 ZZZZZ
CP04 WWWW
CP01 RRRRR
CP03 UUUUU
.
.
.
CPO2 TTTTT
So....i did this->
for(int i=0;i<10;i++)
{
infile.getline(rarray[i].module,4);
cout<<rarray[i].module;
}
where everything listed here are declared properly.It should by right show me something like CP01->rarray[0].module,CP02->rarray[1].module,CP04,CP01,CP03,where each "CP0X" is stored correctly in rarray[i].module.BUT it didn't.I want them reading the data downwards then saving the data correctly into the array,not overflowing into the next array for the name.Can someone please help me with this?Thanks
•
•
Join Date: Aug 2005
Posts: 4
Reputation:
Solved Threads: 0
Here,i did some modifications but the problem persisted.It gave me garbage when i cout the supposedly stoed values to check.
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<fstream> using namespace std; struct student { int subj; int index; char name[21]; float marks[5]; char grade; }; void readStudents(ifstream&,int,student*); int conv (char*); void main() { int length; student slist[20]; ifstream marks("marks.txt"); marks>>length; readStudents(marks,length,slist); } void readStudents(ifstream& infile,int limit,student *slist) { char score[4]; for(int i=0;i<limit;i++) { infile.ignore(3); infile>>slist[i].subj; infile.ignore(3); infile>>slist[i].index; infile.ignore(1); infile.getline(slist[i].name,21,','); for(int j=0;j<4;j++) { infile.getline(score,4,','); slist[i].marks[j]=conv(score); } infile.ignore('\n'); cout<<slist[i].subj; } } int conv(char *arr) { if(arr[0]=='A') return 0; else if(arr[0]=='T') return -1; else if(arr[0]=='1'&&arr[2]=='0') return 100; else return (arr[0]-48)*10+(arr[1]-48); }//this part of the code is another part of the qn.
Last edited by Dave Sinkula; Aug 16th, 2005 at 11:30 am. Reason: Added [code][/code] tags.
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
and use code tags. code not tagged looks horrible and is enough to put me off even looking through it.
•
•
Join Date: Aug 2005
Posts: 4
Reputation:
Solved Threads: 0
Yeah,but my purpose isn't to find a character or integer,but to read from the file.I can read the first CP04,i did infile.ignroe(3)to skip "CP0" and i got '4' in my array,first slot.However,after the first number,i can't store the rest properly,when i cout i got minus values.So can anyone tell me what's wrong??
•
•
Join Date: Aug 2005
Posts: 4
Reputation:
Solved Threads: 0
here:
10
CPO1,S0100,Albert A,85,6592,31
CPO3,S0100,Albert A,77,46,73,74
CPO0,S0101,Candy C,70,97,62,49
CPO0,S0101,Candy C,59,67,42,59
CPO2,S0102,Cecilia C,93,64,34,64
CPO4,S0102,Cecilia C,98,31,66,93
CPO4,S0103,Fanny F,71,50,83,87
CPO3,S0103,Fanny F,70,46,93,56
CPO2,S0104,Alec A,94,99,34,81
CPO4,S0104,Alec A,40,55,59,100
CPO3,S0105,Eric E,62,95,82,39
CPO4,S0105,Eric E,89,60,97,73
CPO3,S0106,Shawn S,91,49,88,89
CPO3,S0106,Shawn S,94,73,76,52
CPO2,S0107,Tiffy T,57,93,56,53
CPO4,S0107,Tiffy T,69,71,45,65
CPO3,S0108,Hua yi,73,39,60,68
CPO1,S0108,Hua yi,98,48,100,47
CPO3,S0109,Flash F,77,35,75,51
CPO1,S0109,Flash F,49,84,64,90
10
CPO1,S0100,Albert A,85,6592,31
CPO3,S0100,Albert A,77,46,73,74
CPO0,S0101,Candy C,70,97,62,49
CPO0,S0101,Candy C,59,67,42,59
CPO2,S0102,Cecilia C,93,64,34,64
CPO4,S0102,Cecilia C,98,31,66,93
CPO4,S0103,Fanny F,71,50,83,87
CPO3,S0103,Fanny F,70,46,93,56
CPO2,S0104,Alec A,94,99,34,81
CPO4,S0104,Alec A,40,55,59,100
CPO3,S0105,Eric E,62,95,82,39
CPO4,S0105,Eric E,89,60,97,73
CPO3,S0106,Shawn S,91,49,88,89
CPO3,S0106,Shawn S,94,73,76,52
CPO2,S0107,Tiffy T,57,93,56,53
CPO4,S0107,Tiffy T,69,71,45,65
CPO3,S0108,Hua yi,73,39,60,68
CPO1,S0108,Hua yi,98,48,100,47
CPO3,S0109,Flash F,77,35,75,51
CPO1,S0109,Flash F,49,84,64,90
•
•
Join Date: Aug 2005
Posts: 14
Reputation:
Solved Threads: 3
•
•
•
•
Originally Posted by DeVilSoul
Yeah,but my purpose isn't to find a character or integer,but to read from the file.I can read the first CP04,i did infile.ignroe(3)to skip "CP0" and i got '4' in my array,first slot.However,after the first number,i can't store the rest properly,when i cout i got minus values.So can anyone tell me what's wrong??
![]() |
Similar Threads
- can someone plz help me with this? (Visual Basic 4 / 5 / 6)
- I NEED SUPPORT **"IMPORTANT"** PLZ HELP (Windows NT / 2000 / XP)
- Windows media player (Windows NT / 2000 / XP)
- Bridge.dll...Make it go away, Plz (Viruses, Spyware and other Nasties)
- can sum1 look @ dis plz (Viruses, Spyware and other Nasties)
- Hijackthis log file - plz help (Viruses, Spyware and other Nasties)
- IE not working...PLZ help :cry: (Web Browsers)
- PLZ help it's urgent! (Web Browsers)
- plz help ppl...... (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Difficult
- Next Thread: fstream to char and int array
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





