babadinding
Cadet 2nd Year
- Registriert
- Apr. 2015
- Beiträge
- 16
hello can someone correct my error in the following program and figure out where i went wrong
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
char text[]= "once upon a time there live a lion and other animals";
int numberof, i,x,quersumme, numberof_byte;
int numberof_e=0, numberof_z=0, numberof_A=0, numberof_M=0, numberof_space=0;
numberof=strlen(text);
numberof_byte=sizeof(text);
for(i=0;i<=numberof;i++){
//x=text;
switch(text){
case 'e': numberof_e=numberof_e+1; break;
case 'z': numberof_z= numberof_z+1; break;
case 'A': numberof_A= numberof_A+1; break;
case 'M': numberof_M=numberof_M+1; break;
case ' ': numberof_space=numberof_space+1; break;
}
}
printf("%s\n", text);
printf("%d\n", numberof);
printf("%d\n", numberof_byte);
printf("the number of e: %d\n", numberof_e);
printf("the number of z: %d\n", numberof_z);
printf("the number of A: %d\n", numberof_A);
printf("the number of M: %d\n", numberof_M);
printf("the number of space: %d\n", numberof_space);
return 0;
}
once upon a time there live a lion and other animals
52
53
the number of e: 6
the number of z: 0
the number of A: 0
the number of M: 0
the number of space: 10
Process returned 0 (0x0) execution time : 0.063 s
Press any key to continue.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
char text[]= "once upon a time there live a lion and other animals";
int numberof, i,x,quersumme, numberof_byte;
int numberof_e=0, numberof_z=0, numberof_A=0, numberof_M=0, numberof_space=0;
numberof=strlen(text);
numberof_byte=sizeof(text);
for(i=0;i<=numberof;i++){
//x=text;
switch(text){
case 'e': numberof_e=numberof_e+1; break;
case 'z': numberof_z= numberof_z+1; break;
case 'A': numberof_A= numberof_A+1; break;
case 'M': numberof_M=numberof_M+1; break;
case ' ': numberof_space=numberof_space+1; break;
}
}
printf("%s\n", text);
printf("%d\n", numberof);
printf("%d\n", numberof_byte);
printf("the number of e: %d\n", numberof_e);
printf("the number of z: %d\n", numberof_z);
printf("the number of A: %d\n", numberof_A);
printf("the number of M: %d\n", numberof_M);
printf("the number of space: %d\n", numberof_space);
return 0;
}
once upon a time there live a lion and other animals
52
53
the number of e: 6
the number of z: 0
the number of A: 0
the number of M: 0
the number of space: 10
Process returned 0 (0x0) execution time : 0.063 s
Press any key to continue.