read data into a link list

can smone plzzzz help me out with this prog.
there r no compilation errors but there's no output of prog. its just showing a blank screen
here's the prog.
#include
#include
#include
#include
struct node
{
int info;
char name[20];
struct node *next;
}*first,*n,*temp;
void main()
{ifstream fin;
fin.open("read.txt",ios::in);
int i,j,choice;
char ch,nam[20];
clrscr();
first=new node;
fin>>i;
do
{fin.get(ch);
}while(fin.get(ch)!=" ");
first->info=i;
fin.get(nam,20);
fin.get(ch);
strcpy(first->name,nam);
first->next=NULL;
printf("Do u want to continue(1 for yes,0 for no)");
cin>>choice;
while(choice==1)
{
temp=first;
while(temp->next!=NULL)
{
temp=temp->next;
}
n=new node;
fin>>i;
do
{fin.get(ch);
}while(fin.get(ch)!=" ");
n->info=i;
fin.get(nam,20);
fin.get(ch);
strcpy(n->name,nam);
fin.get(ch);
n->next=NULL;
temp->next=n;
printf("Do u want to continue(1 for yes,0 for no)");
cin>>choice;
}
temp=first;
printf("Entered list is:");
while(temp!=NULL)
{
cout<<temp->info<<" ";
cout<<temp->name<<"
";

temp=temp->next;

}
fin.close();
getch();
}
in this m suppose to read data 4m a file into a lnklist
file is lyk
1 aaaa
2 bbbbbb
3 ccccc

actually m havin prob while reading the space b/w no. and the string
any kind of help will be highly appreciated


Comments

  • You seem to be heavily mixing C and C++ -- which you should not.
    Replace all of your #include's too...
    [code]
    #include
    #include
    #include

    extern "C" {
    #include // Warning: Not ANSI compatible
    }

    using namespace std;
    [/code]
    Also, why are you using printf() in some areas, and std::cout in others?
    Take all printf()'s out, and take out the above include out.

    I also noticed you are using C string functions (strcpy()) instead of
    just using std::string. Once more, you are mixing C with C++ wich is bad
    practice.

    Mixing C with C++ is like mixing C++ new operator with C free () function,
    which on some systems will cause a memory leak, curruption, or crash. Don't
    do it.

    Also, please post your code using [leftbr]code[rightbr]*your code here*[leftbr]/code[rightbr] tags. They can make your code easier to read. For example:

    [leftbr]code[rightbr]
    [code]
    int main () {
    std::cout << "Notice how text formatting is preserved" << std::endl;
    return 0;
    }
    [/code]
    [leftbr]/code[rightbr]

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.mt2002.sitesled.com]Website :: OS Development Series[rightbr][/link][/size]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion