Thread: Help!!!!

  1. #31
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i get a compile error when i equate it to zero....invalid initializer
    On a hunch, I'd tell you that the initialiser is used to initialise, not assign.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #32
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    ok well i tried the == to assign it to zero..that didnt work either..

  3. #33
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by starvinmarvin
    ok well i tried the == to assign it to zero..that didnt work either..
    That's equality comparison, not assignment.

    What exactly did you try, and how exactly does it not work?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #34
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So what did you do, then? Show and tell.

  5. #35
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    ok it should say like
    'A' 5
    'B' 6

    a being the character and the number being how many times it was found it the random data generated. i save it in an array. but then when i go to print it out i get like

    'O' -17073743537
    '4' 24641436

    it looks like an adresse and there are about 32 so i think i am just not setting the array up correctly like i am missing something

  6. #36
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is a problem with your code. I think you are doing something wrong. You should fix it.

    That's very helpful, isn't it? Likewise, if you want help from us, you need to give us something to work with.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #37
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by starvinmarvin View Post
    ok it should say like
    'A' 5
    'B' 6

    a being the character and the number being how many times it was found it the random data generated. i save it in an array. but then when i go to print it out i get like

    'O' -17073743537
    '4' 24641436

    it looks like an adresse and there are about 32 so i think i am just not setting the array up correctly like i am missing something
    Doesn't look like an address to me -- looks more like random data that happened to be there. And I think you're up to six times being told what's wrong. Show us how this "={0}" didn't work.

  8. #38
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    the code for the whole program is on the first page of this thread

  9. #39
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by starvinmarvin
    the code for the whole program is on the first page of this thread
    And 37 posts later you have made no changes to it at all, despite claiming that you tried some suggestions?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #40
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by starvinmarvin View Post
    the code for the whole program is on the first page of this thread
    Yes. Well. If you won't take any of the twenty-two previous suggestions, why should we give you a twenty-third? You say the one I posted last doesn't work. I KNOW it works, because I am typing this on my very own computer upon which I can compile things. So show us what you tried to do to fix this, because we have suggested fixes. The fact that you say they don't work just means that you have done something weird to them.

  11. #41
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Code:
    int generate(int arr[], int num1, int num2, FILE *pFPOut)
    {
       int linesize = 75;
       int numprinted = 0;
       int i;
       int temp;  
          
        
       printf("The data in test.txt is %d %d.", num1, num2);   
       printf("\n");
       printf("\n");
       srand(num1); 
       for (i = 0; i < num2; i++)
       {  
          temp = rand() % 95 + 32;
          fprintf(pFPOut,"%c", temp);
          printf("%c", temp);
          arr[temp-32]++;
          numprinted++;
         
          if (numprinted >= linesize)
          {
             fprintf(pFPOut,"\n");
             printf("\n");
             numprinted = 0;   
          }
       }
       printf("\n\n");   
    return ;    
    }
    
    //print report to screen 
    void report(int arr[], FILE *pFPOut)
    { 
       int numprinted = 0;
       int i;
       int linesize = 4;   
    
       fprintf(pFPOut,"\n\n");
       for (i = 32; i < 126; i++)
       {   
          numprinted++;
          fprintf(pFPOut,"'%c' %5d", i, arr[i-32]);
          printf("'%c' %5d", i, arr[i-32]);
          {  printf("     ");
             fprintf(pFPOut,"     ");
          }  
             if (numprinted >= linesize)
             {  printf("\n");
                fprintf(pFPOut,"\n");
                numprinted = 0;   
             }
       } 
    printf("\n\n");   
    
    return ;
    }
    whats wrong with this

  12. #42
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by starvinmarvin View Post
    Code:
    int generate(int arr[], int num1, int num2, FILE *pFPOut)
    {
       int linesize = 75;
       int numprinted = 0;
       int i;
       int temp;  
          
        
       printf("The data in test.txt is %d %d.", num1, num2);   
       printf("\n");
       printf("\n");
       srand(num1); 
       for (i = 0; i < num2; i++)
       {  
          temp = rand() % 95 + 32;
          fprintf(pFPOut,"%c", temp);
          printf("%c", temp);
          arr[temp-32]++;
          numprinted++;
         
          if (numprinted >= linesize)
          {
             fprintf(pFPOut,"\n");
             printf("\n");
             numprinted = 0;   
          }
       }
       printf("\n\n");   
    return ;    
    }
    
    //print report to screen 
    void report(int arr[], FILE *pFPOut)
    { 
       int numprinted = 0;
       int i;
       int linesize = 4;   
    
       fprintf(pFPOut,"\n\n");
       for (i = 32; i < 126; i++)
       {   
          numprinted++;
          fprintf(pFPOut,"'%c' %5d", i, arr[i-32]);
          printf("'%c' %5d", i, arr[i-32]);
          {  printf("     ");
             fprintf(pFPOut,"     ");
          }  
             if (numprinted >= linesize)
             {  printf("\n");
                fprintf(pFPOut,"\n");
                numprinted = 0;   
             }
       } 
    printf("\n\n");   
    
    return ;
    }
    whats wrong with this
    Your i loop needs to print 126, so change it to i < 127.

    This won't help your "need to set array to 0 in main" problem, of course.

  13. #43
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    ok i was able to put arr[95] = 0 below where i delcared it and i still get a bunch a crazy numbers.

  14. #44
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by starvinmarvin View Post
    ok i was able to put arr[95] = 0 below where i delcared it and i still get a bunch a crazy numbers.
    Good. That's what you should get. arr[95] doesn't exist. Read the post again. Pay attention to what it says -- more importantly pay attention to where things are and change the line indicated, not some other random line somewhere else.

  15. #45
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    dude just tell me what i need to write to get it to print the frequency..im tired of working on this

Popular pages Recent additions subscribe to a feed