Thread: Whats wrong with my C program?

  1. #16
    Registered User
    Join Date
    Apr 2002
    Posts
    156

    ok....its not a virus......or is it?

    Code:
    #include <stdio.h>          // standard C header
    #include <stdlib.h>         // standard lib
    #include <string>           // header for basic/advance strings
    
    int main(int argc, char *argv[])   // console main
    {                                  // starts console main
    char name[80];                     // string(in C)
    int length=0, i=0;                 // the variable length returns the value of strlen(name) and the variable 'i' is for counters(loops)
    
    printf("Input your name: ");       // instructs user to type in name
    scanf("%s", name);                 // scans keyboard input
    length= strlen(name);              // declares length
    
    printf("Your name is: ");          // prints out name
    while (i < length) {               // starts while loop, while i is lower then length
    printf("%s", name[i]);             // prints each character of the user's name as the array value increases
    i++; }                             // increments the value of 'i'
    
    printf(" and its %d characters long.", length);  // informs user how long his/her name is
    
    printf("\n\n");                    // skips several lines so it wouldn't look sloppy
    system("pause");                   // "Press Enter to continue...." comes up
    return EXIT_SUCCESS;               // EXIT_SUCCESS is pre-defined and tells the compiler that the program hasn't encountered any problems.
    }                                  // ends the console main function
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  2. #17
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    >ok....its not a virus......or is it?
    Hopefully not!

    Code:
    #include <stdio.h>          // standard C header
    #include <stdlib.h>         // standard lib
    #include <string.h>           // header for basic/advance strings
    
    int main(int argc, char *argv[])   // console main
    {                                  // starts console main
    char name[80];                     // string(in C)
    int length=0, i=0;                 // the variable length returns the value of strlen(name) and the variable 'i' is for counters(loops)
    
    printf("Input your name: ");       // instructs user to type in name
    scanf("%s", name);                 // scans keyboard input
    length= strlen(name);              // declares length
    
    printf("Your name is: ");          // prints out name
    while (i < length) {               // starts while loop, while i is lower then length
    printf("%c", name[i]);             // prints each character of the user's name as the array value increases
    i++; }                             // increments the value of 'i'
    
    printf(" and its %d characters long.", length);  // informs user how long his/her name is
    
    printf("\n\n");                    // skips several lines so it wouldn't look sloppy
    system("pause");                   // "Press Enter to continue...." comes up
    return EXIT_SUCCESS;               // EXIT_SUCCESS is pre-defined and tells the compiler that the program hasn't encountered any problems.
    }                                  // ends the console main function
    Got it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Maze Program - What am I doing wrong?
    By Gipionocheiyort in forum C++ Programming
    Replies: 20
    Last Post: 08-02-2007, 01:31 PM
  2. Replies: 5
    Last Post: 01-13-2007, 02:14 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 09:57 AM
  5. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 05:09 PM