Like Tree1Likes
  • 1 Post By Salem

print string

This is a discussion on print string within the C Programming forums, part of the General Programming Boards category; What you should do is take the loop out of main and put it into a function. The purpose of ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Unhappy print string

    What you should do is take the loop out of main and put it into a function. The purpose of the function is to accept a string then display the individual characters of the string to the screen one at a time.
    1. Prompt for and input a string value from the keyboard.
    2. Pass this value to a user defined function that will display each character in the string on a separate line of the screen.
    3. In main, thank the user for using your program.
    The user function will need to:
    1. Accept the string as an input parameter. Name this string variable newstring
    2. Create a variable named index and initialize it to zero (0)
    3. While (newstring[index] does not equal \0).
    i. Display the character at newstring[index] followed by a NL
    ii. Increment index
    End Loop
    4. Return to main.

    __________________________________________________

    where am i making mistake ???
    __________________________________________________

    Code:
    #include<stdio.h>
    
    
    int DisplayCharacter(char newstring[]);      // Prototype Declaration
    
    
    int main()
    {
        char newstring[80];
    
    
        printf("Enter the String: ");
        gets(newstring);
    
    
        printf("Thank You\n\n\n");
    
    
    }
    
    
    //Writing function
    int DisplayCharacter(char newstring[])
    {
        int index = 0;
        while(newstring[index] != '\0')
        {
            printf("%c\n",newstring[index]); // prints the first word of the string
            index++;
        }
        return (index);
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    The only thing missing is this.
    2. Pass this value to a user defined function that will display each character in the string on a separate line of the screen.


    And SourceForge.net: Gets - cpwiki
    Miss Punjaban likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    Thank You

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. print first word of the string
    By Miss Punjaban in forum C Programming
    Replies: 3
    Last Post: 04-12-2013, 06:09 AM
  2. string print from 2 files
    By l_l in forum C Programming
    Replies: 4
    Last Post: 07-25-2012, 02:51 PM
  3. How can I print a string backwards?
    By ahmedbatty in forum C Programming
    Replies: 3
    Last Post: 12-07-2011, 08:33 AM
  4. Why i can print string beyond the range?
    By wonderwall in forum C Programming
    Replies: 2
    Last Post: 11-07-2011, 05:19 AM
  5. how to print only N numbers of string
    By umen242 in forum C Programming
    Replies: 1
    Last Post: 06-26-2008, 12:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21