I am creating a program to add large numbers in C++.
I want to take the number from a file and store it in a linked list, but if there is a decimal I want to just keep the record of index of the dot and not store it into the list.
So, when the while loop encounters a dot, it just keeps the index and skips to the next one.
For some reason, my code gets stuck in infinite loop.
Here is my code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct node
{
int data;
node *next;
};
int main(int argc, char *argv[]){
int digit;
node * head1 = NULL;
node * tail1 = NULL;
node * temp1 = NULL;
ifstream fStream;
fStream.open(argv[1]);
while(!fStream.eof()){
fStream >> digit;
if(!isdigit(digit))
{
fStream >> digit;
cout <<"done";
}
//fStream >> digit;
temp1 = new node();
temp1->data = digit;
temp1->next = head1;
head1 = temp1;
}
fStream.close();
node * head2 = NULL;
node * tail2 = NULL;
node * temp2 = NULL;
ifstream fStream1;
fStream1.open(argv[2]);
cout<<argv[2]<<endl;
while(!fStream1.eof()){
fStream1 >> digit;
temp2 = new node();
temp2->data = digit;
temp2->next = head2;
head2 = temp2;
}
fStream1.close();
while(temp1!=NULL){
cout <<temp1->data<<" ";
temp1 = temp1->next;
}
cout<<endl;
while(temp2!=NULL){
cout <<temp2->data<<" ";
temp2 = temp2->next;
}
cout<<endl;
}
Can anyone help?