string

Status
Für weitere Antworten geschlossen.

babadinding

Cadet 2nd Year
Registriert
Apr. 2015
Beiträge
16
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void howmany_characters(char count [], int numberof){

int i,numberof_characters=0, numberof_space=0, miscellaneous=0;

for(i=0; i<numberof; i++){

if((count>=65 && count<=90) || (count>=97 && count<=122)){
numberof_characters;
numberof_characters=numberof_characters+1;
}
else if(count= ' '){
numberof_space;
numberof_space=numberof_space+1;
}
else
{
miscellaneous;
miscellaneous=miscellaneous+1;
}

}
printf("the number of characters in the string is : %d\n", numberof_characters);
printf("the number of spaces in the string is: %d\n", numberof_space);
printf("the number other characters in the string is: %d\n", miscellaneous);
}

void character_determinator(char text[], int length){
int i,result, num, alphabet,others;

for(i=0; i<length;i++){
if(text>=0 || text<=9){
result=0;
printf(" the given character is a number: %d\n", result);
break;
}
else if((text>=65 && text<=90) || (text>=97 && text<=122)){
result=1;
printf("the given character is an alphabet: %d\n",result);
break;
}

else {
result=2;

printf("the character is miscellaneous: %d\n", result);
break;
}
}

}





int main(){

char count1[]="hello world";
int howbig=strlen(count1), result2;
printf("the given string:%s\nthe length of the string: %d\n", count1, howbig);
howmany_characters(&count1[0],howbig);
printf("bitte geben sie ein zeichen ein:\n");

fgets(count1,howbig,stdin);
character_determinator(&count1[0], howbig);
//character_determinator(result);


return 0;
}


can somebody figure out for me what the error is because if i compile and run the program this is what it is giving me as output even though a character or other characters are given:
bandeh@SLZ06 ~/Desktop $ ./stringcount2
the given string:hello world
the length of the string: 11
the number of characters in the string is : 10
the number of spaces in the string is: 1
the number other characters in the string is: 0
bitte geben sie ein zeichen ein:
g
the given character is a number: 0
 
Zuletzt bearbeitet:
2 Threads?
 
Status
Für weitere Antworten geschlossen.
Zurück
Oben