minor change causes crash 
Author Message
 minor change causes crash

I thought that prog2 is equivalent to prog1 as the only thing I had
done was make a function by combining two earlier functions, but prog1
runs and prog2 crashes horribly, I have compiled with both bcc and gcc
facing the same result.
Confusingly while debugging (with turbo de{*filter*}) prog2 terminates
normally with the expected results. Can this behavior depend on how I
have written the functions ReadFileIntoList,MakeMatFromList , it is
simply not clear to me how only one of the program works and the other
does not.
I am totally at my wits end and frustrated.
Thanks in advance for any help/advice/hints .

/******prog1***********/
#include <stdio.h>
#include "structs.h"

int main()
{
    char s[256];  
    FILE *fp;
    int lines,cols;
        PList pl;
        PMAT pm;
    printf("Give file name:");
    scanf("%s",s);
    fp=fopen(s,"rb");
    if (fp==NULL)
    {
        fprintf(stderr,"Unable to open file");
        return 1;
    }
    pl=ReadFileIntoList(fp,&lines,&cols);
    pm=MakeMatFromList(pl,lines,cols);
    WriteMat(pm);
    return 0;

Quote:
}

/******prog2*********/
#include <stdio.h>
#include "structs.h"

PMAT ReadFileIntoMat(FILE *fp,int *nrows,int *ncols)
{
        PList pl;
        PMAT pm;
        int lines,cols;
        pl=ReadFileIntoList(fp,&lines,&cols);
        pm=MakeMatFromList(pl,lines,cols);
        *nrows=lines;
        *ncols=cols;
        return pm;

Quote:
}

int main()
{

    FILE *fp;
    int lines,cols;
    char s[256];
    printf("Give file name:");
    scanf("%s",s);
    fp=fopen(s,"rb");
    if (fp==NULL)
    {
        fprintf(stderr,"Unable to open file");
        return 1;
    }
    pm=ReadFileIntoMat(fp,&lines,&cols);
    WriteMat(pm);
    return 0;

Quote:
}



Mon, 15 Dec 2003 11:15:32 GMT  
 minor change causes crash

Quote:

> I thought that prog2 is equivalent to prog1 as the only thing I had
> done was make a function by combining two earlier functions, but prog1
> runs and prog2 crashes horribly, I have compiled with both bcc and gcc
> facing the same result.
> Confusingly while debugging (with turbo de{*filter*}) prog2 terminates
> normally with the expected results. Can this behavior depend on how I
> have written the functions ReadFileIntoList,MakeMatFromList , it is
> simply not clear to me how only one of the program works and the other
> does not.
> I am totally at my wits end and frustrated.
> Thanks in advance for any help/advice/hints .

> /******prog2*********/
> #include <stdio.h>
> #include "structs.h"

> PMAT ReadFileIntoMat(FILE *fp,int *nrows,int *ncols)
> {
>         PList pl;
>         PMAT pm;
>         int lines,cols;
>         pl=ReadFileIntoList(fp,&lines,&cols);
>         pm=MakeMatFromList(pl,lines,cols);
>         *nrows=lines;
>         *ncols=cols;
>         return pm;
> }

> int main()
> {

>     FILE *fp;
>     int lines,cols;
>     char s[256];
>     printf("Give file name:");

fflush(stdout);

Quote:

>     scanf("%s",s);
>     fp=fopen(s,"rb");
>     if (fp==NULL)
>     {
>         fprintf(stderr,"Unable to open file");
>         return 1;
>     }
>     pm=ReadFileIntoMat(fp,&lines,&cols);
>     WriteMat(pm);
>     return 0;
> }

In function main, I do not see a declaration of pm.

--
Al Bowers
Tampa, FL  USA
comp.lang.c faq: http://www.*-*-*.com/ ~scs/C-faq/top.html

http://www.*-*-*.com/



Mon, 15 Dec 2003 14:55:58 GMT  
 minor change causes crash
Quote:

> I thought that prog2 is equivalent to prog1 as the only thing I had
> done was make a function by combining two earlier functions, but prog1
> runs and prog2 crashes horribly, I have compiled with both bcc and gcc
> facing the same result.
> Confusingly while debugging (with turbo de{*filter*}) prog2 terminates
> normally with the expected results. Can this behavior depend on how I
> have written the functions ReadFileIntoList,MakeMatFromList , it is
> simply not clear to me how only one of the program works and the other
> does not.
> I am totally at my wits end and frustrated.
> Thanks in advance for any help/advice/hints .

> /******prog1***********/
> #include <stdio.h>
> #include "structs.h"

> int main()
> {
>     char s[256];
>     FILE *fp;
>     int lines,cols;
>         PList pl;
>         PMAT pm;
>     printf("Give file name:");
>     scanf("%s",s);
>     fp=fopen(s,"rb");
>     if (fp==NULL)
>     {
>         fprintf(stderr,"Unable to open file");
>         return 1;
>     }
>     pl=ReadFileIntoList(fp,&lines,&cols);
>     pm=MakeMatFromList(pl,lines,cols);
>     WriteMat(pm);
>     return 0;
> }

> /******prog2*********/
> #include <stdio.h>
> #include "structs.h"

> PMAT ReadFileIntoMat(FILE *fp,int *nrows,int *ncols)
> {
>         PList pl;
>         PMAT pm;
>         int lines,cols;
>         pl=ReadFileIntoList(fp,&lines,&cols);

Well, right off the bat, we have an infinite recursion in the line
above...do a `hand trace' through the code and you'll see what I mean.

- Show quoted text -

Quote:
>         pm=MakeMatFromList(pl,lines,cols);
>         *nrows=lines;
>         *ncols=cols;
>         return pm;
> }

> int main()
> {

>     FILE *fp;
>     int lines,cols;
>     char s[256];
>     printf("Give file name:");
>     scanf("%s",s);
>     fp=fopen(s,"rb");
>     if (fp==NULL)
>     {
>         fprintf(stderr,"Unable to open file");
>         return 1;
>     }
>     pm=ReadFileIntoMat(fp,&lines,&cols);
>     WriteMat(pm);
>     return 0;
> }

HTH,
--ag
--
Artie Gold, Austin, TX  (finger the cs.utexas.edu account for more info)

--
The King is dead. But the Boogie Chillun live.


Mon, 15 Dec 2003 11:40:50 GMT  
 minor change causes crash
I am sorry I had copy pasted the code in two separte parts , the declaration of
pm got lost being at the junction .
So here is the corrected version . It was copy-pasting error.
/******prog1***********/
#include <stdio.h>
#include "structs.h"

int main()
{
char s[256];  
FILE *fp;
int lines,cols;
PList pl;
PMAT pm;
printf("Give file name:");
scanf("%s",s);
fp=fopen(s,"rb");
if (fp==NULL)
{
fprintf(stderr,"Unable to open file");
return 1;

Quote:
}

pl=ReadFileIntoList(fp,&lines,&cols);
pm=MakeMatFromList(pl,lines,cols);
WriteMat(pm);
return 0;

Quote:
}

/******prog2*********/
#include <stdio.h>
#include "structs.h"

PMAT ReadFileIntoMat(FILE *fp,int *nrows,int *ncols)
{
PList pl;
PMAT pm;
int lines,cols;
pl=ReadFileIntoList(fp,&lines,&cols);
pm=MakeMatFromList(pl,lines,cols);
*nrows=lines;
*ncols=cols;
return pm;

Quote:
}

int main()
{

FILE *fp;
int lines,cols;
char s[256];
PMAT pm;
printf("Give file name:");
scanf("%s",s);
fp=fopen(s,"rb");
if (fp==NULL)
{
fprintf(stderr,"Unable to open file");
return 1;

Quote:
}

pm=ReadFileIntoMat(fp,&lines,&cols);
WriteMat(pm);
return 0;
Quote:
}



Mon, 15 Dec 2003 12:23:17 GMT  
 minor change causes crash

Quote:

> > PMAT ReadFileIntoMat(FILE *fp,int *nrows,int *ncols)
> > {
> >         PList pl;
> >         PMAT pm;
> >         int lines,cols;
> >         pl=ReadFileIntoList(fp,&lines,&cols);
> Well, right off the bat, we have an infinite recursion in the line
> above...do a `hand trace' through the code and you'll see what I mean.

Really?

Quote:
> >         pm=MakeMatFromList(pl,lines,cols);
> >         *nrows=lines;
> >         *ncols=cols;
> >         return pm;
> > }
> > int main()
> > {
[snip]
> >     pm=ReadFileIntoMat(fp,&lines,&cols);
> >     WriteMat(pm);
> >     return 0;
> > }

        david

--
If 91 were prime, it would be a counterexample to your conjecture.
    -- Bruce Wheeler



Mon, 15 Dec 2003 13:32:39 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. /CLR option causing MMC Property Page to crash.

2. CControlBar::m_bAutoDelete=TRUE causes shutdown crash porting from VC6 to VC7

3. Local CPoint causes crash on exit

4. Converting some DSPs to VCPROJ causes crash?

5. ATL virtual destructor and events causes crash

6. Too many globals causing wierd crashes (Watcom 10.0)

7. _ATL_DEBUG_INTERFACES causes crashes when hooking up events

8. Call CreateThread function in NT 4.0, it cause crash Explorer for Shell Extionsion

9. ATL Control caused the application crash

10. ActiveX Event causes VB compiled apps to crash

11. Compiling atl component in VB is causing crash

12. DAO:DeleteIndex causes Release mode crash

 

 
Powered by phpBB® Forum Software