How to Count Char on Input Sentence

Saturday, October 10, 2009

This is one ef the C code that will count the char of sentence that we've input before.

#include<stdio.h>
#define MAKS 256

int main(void){
    int i, jumkar = 0;
    char teks[MAKS];


    puts("Please insert a sentence (max 256 char): ");
    puts("I'll count sum of char on its sentence. ");
    fgets(teks, sizeof teks, stdin); //input from keyboard
    for(i=0;teks[i];i++)
        jumkar++;
    printf("\n Sum of char = %d\n", jumkar);

    return 0;
}


And this is the result:


0 comments:

Post a Comment

 
 
Copyright © Welcome