0

The problem is that my program crasches when at line 13. Pot10 i an int and lgth is an int so whats the problem? I can't figure it out:(

typedef struct ArrInt{
int intM[100], lgth;
} megaint;

void scanMeg(megaint *x){
     int Pot10 = 0, ret,IntArr[100];
     char c;
     while( (c = getchar()) != '\n'){
            IntArr[Pot10] = atoi(&c);
            Pot10++;
     }

     x->lgth = Pot10;

     for(ret=0; Pot10 >= 0; Pot10--, ret++)
         x->intM[ret] = IntArr[Pot10];
}
2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Salem
0

atoi() expects a pointer to a char array, containing a \0 char at some point?
A single char doesn't work. IntArr[Pot10] = c - '0';

0

Strangely that doesn't crasch the program but x->lgth = Pot10; does crasch the program...

0

Well then, you need to show how you call the function.

If you have scanMeg( &megaint ); I can't see a problem.

But if you have

ArrInt *myBigInt;
scanMeg( myBigInt );

then you're on a road to nowhere with unallocated memory and uninitialised pointers.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.