Thread: Simple array question

  1. #1
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231

    Simple array question

    I am making a program which prints a character from an array with printf but it is just spitting out "random" symbols.
    this is how I am doing it.
    Code:
    printf("%c",info[get]);
    get is an int that says which character to get.
    Thanks
    all my code. (you will probably wonder what I am doing. It is the beginning of a scrambled word unscrambler . Still have to get the math of it down though.)

    Code:
    #include <stdio.h>
    
    int main()
    {
        int lasttime = 0;
        int stoploop;
        int check;
        int word = 25;
        FILE *pfile;
        int get = 0;
        char getit;
        char point[50];
        char info[20];
        
        scanf("%s",&point);
        
        pfile = fopen("find","w");
        fprintf(pfile,"%s",point);
        fclose(pfile);
        pfile = fopen("find","r");
        
        while((getit = fgetc(pfile))!= EOF)
        {
                     info[get];
                     get++;
        }
        
        stoploop = get + 1;
        while(check<=word)
        {
                          if(get == stoploop)
                          {
                                 
                                 get = lasttime + 1;
                                 get = lasttime;
                                 printf("\n");
                          }
                          else if(get < 6)
                          {
                               
                               
                               printf("%c",info[get]);
                               check++;
                               get++;
                               
                          }     
        }
        
        getch();
        return 0;
        
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    info[] isn't initialized nor been assigned to in the code, and you wonder about those strange symbols.

  3. #3
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    well.....that embarrassing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Question: sizeof() problem in function
    By Xeyide in forum C Programming
    Replies: 3
    Last Post: 09-04-2009, 12:05 AM
  2. Hopefully simple question, input streams
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2006, 01:59 PM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  4. simple array question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2002, 10:43 PM
  5. simple array question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 04:46 PM