خرید بک لینک

Vote count: 0

I just started programming and came up with a program to count the number of characters in an input.

The code is as below:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()

{
int number = 0;
int counter = 0;
char sentence[20];

printf("Enter a sentence: ");
scanf("%s", sentence);


while ( sentence[number] != 'n' )
{
    counter += 1;
    number += 1;

}


printf("no. of characters in sentence you just typed: %d", counter);

retu 1;

}

This program has a strange behavior that I caot understand. It compiles without error but no matter how many characters I type or what character is entered, it shows the no. of characters as 817.

I am curious as to why 817? Its really weird haha. Also please enlighten me on how can I improve my code since it did not perform as expected.

Thanks :)

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 15 خرداد 1395 ساعت: 15:22

صفحه بندی