Thread: array size problem

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    16

    array size problem

    hi all
    i am making a getword and line number program and right now i am working on some parts of the program but something weird has happened this is my code and i get a windows runtime error when i change

    char heckman[64]; to this:
    char heckman[more than 64]



    Code:
    #include<stdio.h>
    
     
    main(){
        int a,b=0,c=0,x=0,e=0;
        char heckman[64];  
         char *manyak[50];   
           
           
           while((a=getchar())!=EOF)
             heckman[b++]=a;
              heckman[b]=0;
            /*     read the input        */
          
          
            while(c<b){
               *((*manyak)+(c))=heckman[c];
               
                   
                   c++; 
                   }
              
           *((*manyak)+(c))=0;
          
           printf("%s",*manyak);
           
           
           getchar();
           return 0;
           }
    anybody knows why is that?
    thanx in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    That manyak is just an array of pointers (to random places in memory, since you don't initialise it), and that you're spraying characters all over that random memory "uzzi style".

    Before it was crashing, that was just you being lucky rather than good.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    81
    That is pretty bad code. I don't think it's ever necessary to get into statements like this: *((*manyak)+(c))


    Unless you purposely want to confuse yourself and others.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  2. size of array
    By goran00 in forum C Programming
    Replies: 38
    Last Post: 04-02-2008, 09:57 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Replies: 42
    Last Post: 12-19-2004, 08:59 AM