Hey,
quick question. I am reading in numbers from a file. I need to read them in one at a time. In the file there are spaces and endlines that I need to get rid of. I have tried several ways of doing this but none work. Any help would be appreciated.
Here is what I have so far:
Code:#include <iostream.h> #include <fstream.h> #include <stdlib.h> #include <string.h> //global variables ifstream infile; ofstream outfile; struct node; typedef node* nodeptr; struct node { int digit; char num; nodeptr next; }; //prototypes void readIn(nodeptr &,nodeptr &); int charConvert(char);//num conversion fxn int main() { nodeptr start, last; readIn(start,last); return 0; } //Functions void readIn(nodeptr &start,nodeptr &last) { char c,d; nodeptr current; char temp; infile.open("lnums.dat"); if(!infile) { cout << "error" << endl; exit(1); } while(!infile.eof()) { //c=infile.get(temp); c=(char)infile.get(); if((c==' ')&&(c=='\n')) { temp=c; } else { d=c; } cout << d; //START sorting current=new node; //strcpy(current->num,temp); current->num=temp; current->next=start; start=current; int charConvert(temp); } } int charConvert(char a) { int x; x=a-48; return x; }



LinkBack URL
About LinkBacks



Guess my way didn't do it any better either...