Thread: need help in passing strings to functions..

  1. #1
    Registered User nyekknyakk's Avatar
    Join Date
    Aug 2010
    Posts
    35

    need help in passing strings to functions..

    Code:
    int main() {
    char text1[SIZE] = {"The quick brown fox jumps over the lazy dog."};
    printf("The quick brown fox jumps over the lazy dog\n");
    printf("Input the text above:\n");
    gets(input);
    check(input, text1);
    printf("Score: %g\n", score);
    }
    
    void check(char input[], char text[]) {
    	
    for (i=0; i<SIZE; i++)
    for (j=0; j<SIZE; j++) {
    words[i][j] = '\0';
    cwords[i][j] = '\0';
    }
    
    for (c=0, i=0, j=0; input[c] != '\0'; c++, j++) {
    if (input[c] == ' ') {
    words[i][j] = '\0';
    c++;
    i++;
    if (i>=10) i=0;
    j=0;
    }
    words[i][j] = input[c];
    }
    		
    for (c=0, i=0, j=0; text[c] != '\0'; c++, j++) {
    if (text[c] == ' ') {
    cwords[i][j] = '\0';
    c++;
    i++;
    if (i>=10) i=0;
    j=0;
    }
    cwords[i][j] = text[c];
    }		
    
    for (c=0, score=0; words[c] != '\0'; c++)
    if (strcmp(words[c], cwords[c])==0) score++;
    }
    well, that's much of the code so far.. it checks wheter the user inputted the correct string by comparing the words of each strings.. it also compiled but it crashes everytime i run the program.. is there anything wrong?
    Thanks!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Words array is not declared.

  3. #3
    Registered User nyekknyakk's Avatar
    Join Date
    Aug 2010
    Posts
    35
    oh.. this is just part of the program! as i've said earlier, it already compiled.. the problem is when i run the program.. it always crashes when it goes from the main function to the check function!

    please assume that everything else are declared..

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    How is input defined in main()?

    Jim

  5. #5
    Registered User nyekknyakk's Avatar
    Join Date
    Aug 2010
    Posts
    35
    come on guys, i didn't copy the whole code so that the important parts will be the only things here.. will you please answer the question?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    We can not answer the question without some added information which you do not seem to want to supply. You are probably overwriting some memory location that your program does not own.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with passing strings to a member function
    By lesterMUNSON in forum C++ Programming
    Replies: 2
    Last Post: 08-13-2009, 12:42 PM
  2. Passing strings to functions and modifying them
    By diddy02 in forum C Programming
    Replies: 6
    Last Post: 08-11-2008, 01:07 AM
  3. Passing from functions in classes to another function in another class?
    By Robert_Sitter in forum Windows Programming
    Replies: 1
    Last Post: 12-13-2005, 07:46 AM
  4. passing strings from functions as the "return" part
    By fraktal in forum C Programming
    Replies: 8
    Last Post: 12-13-2005, 01:38 AM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM