What's wrong with my code?

Discussion in 'Programming General' started by -------owned-------, Aug 18, 2008.

What's wrong with my code?
  1. Unread #1 - Aug 18, 2008 at 4:05 AM
  2. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

    -------owned------- Guru
    Banned

    What's wrong with my code?

    Code:
    #include <stdio.h>
    #include <unistd.h>
    char string[50];
    char string2[60];
    int count = 0;  
    void SlowPrint(char thestring[]) {
             while (thestring[count] != '\0') { 
        count++;  
        printf(thestring[count]);
        sleep(50);
    
    }
        return;
           }
    int main(char** argv) {
    scanf("%s", &string2 );
    strcpy(string,string2);
    SlowPrint(string);
    }
    
    It just won't work as supposed. :(
     
  3. Unread #2 - Aug 19, 2008 at 1:23 PM
  4. Guru Programmer
    Referrals:
    0

    Guru Programmer Guest

    What's wrong with my code?

    does the compiler shows errors, give us details..
     
  5. Unread #3 - Aug 19, 2008 at 2:45 PM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    What's wrong with my code?

    The Sleep() function has a capital letter and also requires a certain library file to be included. I am using Dev-CPP/MingW compiler and it required that I use #include<windows.h>.

    Also, you were complicating yourself where you didn't have to with your printing function so I reworked it to be simpler. Hopefully this will be of help to you and feel free to ask more questions.:)

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    char strOriginal[50];
    char strCopy[50];
    
    void SlowPrint(char strArray[]) {
             for(int i = 0; strArray[i] ; i++) { // Loop through our string array parameter
                 printf("%c", strArray[i]); // Print out the character the loop is at
                 Sleep(1000); // Wait for 1000 milliseconds
             }
             Sleep(2000); // Wait for 2000 milliseconds now that it has been typed
             
    }
    int main() {
        while (1) { // Keep looping so the program doesn't simply close after one go
        scanf("%s", strOriginal ); // Get the user to input a string
        strcpy(strCopy, strOriginal); // Copy that string into a second variable
        SlowPrint(strCopy); // Slowly print out the string
        }
    }
    
     
  7. Unread #4 - Aug 21, 2008 at 12:59 PM
  8. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

    -------owned------- Guru
    Banned

    What's wrong with my code?

    Thank you. :)
    I used the Dev-C++ IDE too.
    I didn't need to include windows.h.
    The problem was that I didn't include "%c" in the printf.
    (Someone on an IRC helped me).
    Thanks for reworking my function.
     
< When I try to download VB | My First Simple Browser >

Users viewing this thread
1 guest


 
 
Adblock breaks this site