Character array help

This is a discussion on Character array help within the C Programming forums, part of the General Programming Boards category; Hi, i am currently trying to write a program that can accept 3 input strings and perform different tasks based ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Thumbs up Character array help

    Hi, i am currently trying to write a program that can accept 3 input strings and perform different tasks based upon it. I currently have written a program that will scan what the user inputs and display how many characters have been inputted and also the amount of spaces to differientiate between strings. I have also set a limit to stop reading the input after 64 characters.

    The main problem I am facing is to differientiate one string from another as the program is meant to display a message saying that the input is too long if one of the strings has more than 30 characters.

    This program also needs to identify if the third letter of each string is upper case or lower case and then depending on what it is change the entire word to that case.

    I know i must use isupper / islower and toupper/tolower but not sure how to correctly implement this into my program.

    Atm the this is what i have:

    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<string.h>
    
    int main(void)
    {
    
    char string_input[65] = { '\0' };
    char character;
    int count, space;
    
    	if ( scanf( "%64c", string_input ) > 0 )
    {
    	printf( "The Length of your input is %d \n", strlen (string_input) );
    
    space = 0;
    
    	for ( count = 0; count < strlen( string_input ); count++)
    	{	character = string_input[ count ];
    
    if  (isspace ( character ) )
    space++;
    
    	}
    
    printf( "Your input found %d spaces \n", space );
    
    }
    
    
    }

    I know it seems a lot to ask but any pointers would be greatly appreciated.

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Fix your indentation.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    [QUOTE=tleverington1;987263]
    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<string.h>
    
    int main()
    {
    
    char string_input[65] = {0};
    char character;
    int count, space;
    
    	if ( scanf( "%64s", string_input ) )
    {
    	printf( "The Length of your input is %d \n", strlen (string_input) );
    
    	for ( count = space = 0; count < strlen( string_input ); count++)
    	{
    
    if  (isspace ( string_input[ count ] )
    space++;
    
    	}
    
    printf( "Your input found %d spaces \n", space );
    
    }
    
    return 0;
    }

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Now the real challenge is to enter a space character using the %s conversion format
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character Array comparison
    By magda3227 in forum C Programming
    Replies: 7
    Last Post: 07-09-2008, 08:36 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

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