charactor count wthout getche function..?

This is a discussion on charactor count wthout getche function..? within the C Programming forums, part of the General Programming Boards category; #include<stdio.h> #include<conio.h> void main() { int count=0; printf("\n\tType any phrase"); while(getche() !=13) //13 is For enter key { count++; } ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    12

    charactor count wthout getche function..?

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int count=0;
    printf("\n\tType any phrase");
    while(getche() !=13) //13 is For enter key
    {
    count++;
    }
    printf("\nCharactor count is =%d",count);
    getch()
    }
    out put

    Type any phrase
    CAT
    charactor count is 3

    i want to count the charactors without using the getche() function. Is there any way to make the program to count the charactors without using getche()..? if yes then please write the programmm.i shall be soo much thankful to you.
    thanks in advance...

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    main( ) {
    
        char word[ 64 ];
    
        printf( "Enter the word: " );
        scanf( "%s", word );
    
        printf( "The # of characters is %d", strlen( word ) );
    
        system( "pause" );
    
    }
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    You could use the strlen function (remember to put the string.h header file) to read the number of characters. Example:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
         char phrase[150];        \\array size
         int size;
    
         printf("Type any phrase: ");
         scanf("%s",&phrase);   \\you can also use gets if you want
         size=strlen(phrase);
         
         printf("The size of the phrase is: %i",size);
    
         return 0;
    }
    Last edited by James00; 05-17-2003 at 10:24 PM.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    This snippet outputs all the characters in a file. I'll leave it to you to change it to count them instead. Of course, as it is, it outputs spaces, number and characters alike. You might want to only be counting characters (for example):
    Code:
    int c;
      
    while ((c = fgetc(fp)) != EOF)
    {
      putchar (c);
    }
    Also, read this
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM

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