Like Tree1Likes
  • 1 Post By Adak

Capitalize words in c

This is a discussion on Capitalize words in c within the C Programming forums, part of the General Programming Boards category; I'm making a program that will input for a string and capitalize the content of the string..can u help me ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    7

    Lightbulb Capitalize words in c

    I'm making a program that will input for a string and capitalize the content of the string..can u help me figure out what's wrong in my code:

    Code:
    #include<stdio.h>
    #include<ctype.h>
    int i;
    main()
    {char namea[100];
     clrscr();
     scanf("%d",namea[i]);
     for(i=1;i<=namea[i];i++){
        namea[i]=toupper(namea[i]);
        printf("%s",namea[i]);
        }
     getch();
    }



    please help me..

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by ikkin28 View Post
    I'm making a program that will input for a string and capitalize the content of the string..can u help me figure out what's wrong in my code:

    Code:
    #include<stdio.h>
    #include<ctype.h>
    int i;
    main()
    {char namea[100];
     clrscr();
     scanf("%d",namea[i]);
     for(i=1;i<=namea[i];i++){
        namea[i]=toupper(namea[i]);
        printf("%s",namea[i]);
        }
     getch();
    }



    please help me..

    1) int main(void) at the start of the program
    2) return 0 at the end of the program

    3) namea is a string, don't scanf() it as an integer, use the string format: %s

    4) remove the index from namea, in the scanf() line of code

    5) arrays in C always begin with 0, not 1. So remove the 1 from the initial assignment in the for loop, and replace it with 0.

    6) move the printf() line of code, OUTSIDE the for loop, or you will be doing things you don't want.

    Namea[i] is a char, it's not a string. Just print the char inside the for loop, and or print the entire string after the changes, after the for loop has finished.
    Last edited by Adak; 09-26-2011 at 07:18 AM.
    MK27 likes this.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    7
    why does it print only the word NULL?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The string format you're asking to be printed, doesn't exist as a single char. A string MUST have 1 char, and 1 end of string char: '\0', (which conceptually is a NULL value), at least.

    Post your updated code, if it's ready.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 10-01-2010, 04:09 PM
  2. Capitalize first letter of every word in .txt file
    By crazygopedder in forum C Programming
    Replies: 9
    Last Post: 10-15-2008, 12:09 PM
  3. Reading words and analyzing words from file
    By desmond5 in forum C Programming
    Replies: 7
    Last Post: 02-26-2008, 02:51 PM
  4. extracting words from an array of words
    By axon in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 10:21 PM
  5. more capitalize char help needed
    By hlens in forum C++ Programming
    Replies: 4
    Last Post: 11-09-2001, 05:19 PM

Tags for this Thread


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