The following code produces segmentation fault at runtime.
-----------------------------CODE---------------------------------------------
#include <stdio.h>
#include <string.h>
main()
{
        char * strArray[2];
        printf("Enter 1:");
        scanf("%s",strArray[0]);
        printf("Enter 2:");
        scanf("%s",strArray[1]);
}

However the following code does not,
-----------------------------CODE---------------------------------------------
#include <stdio.h>
#include <string.h>
main()
{
        char * strArray[2];
        printf("Enter 1:");
        scanf("%s",strArray[0]);
        printf("Enter 2:");
        scanf("%s",strArray[1]);
        int x = 0;
}

-----------------------------ERROR--------------------------------------------
Enter 1:hello
     15669:     symbol=__cxa_finalize;  lookup in file=./stringEx1.s
     15669:     symbol=__cxa_finalize;  lookup in file=/usr/lib/libstdc++.so.6
     15669:     symbol=__cxa_finalize;  lookup in
file=/lib/tls/i686/cmov/libm.so.6
     15669:     symbol=__cxa_finalize;  lookup in file=/lib/libgcc_s.so.1
     15669:     symbol=__cxa_finalize;  lookup in
file=/lib/tls/i686/cmov/libc.so.6
Segmentation fault


-- 
           Summary: Segmentation fault while using array of character
                    pointers.
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stevekoe at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34362

Reply via email to