I think this code almost works but for some reason it doesn't wait after the second question? It is suppost to ask you what number you would like to look for in a string then ask you to input the string. The thing is on the second question where it ask you for the string it doesn't wait for an input???
Code:
#include <stdio.h>
#include <stdlib.h>
void count(int number,char *array,int lenght);
int main(){
int input,lenght=0,x=0;
char buffer[200];
char num[2];
printf("What single digit integer would you like to look for in a string
: ");
fgets(num,sizeof(num),stdin);
sscanf(num,"%i",&input);
printf("What is the string you would like to have?\n");
fgets(buffer,sizeof(buffer),stdin);
while(buffer[x]!='\n'){
++x;
}
count(input,buffer,x);
return 0;
}
void count(int number,char *array,int length){
auto int count=0; /*counter for while loop*/
auto int total=0; /*total number of times that number is in the string*/
while(1){
if(array[count]=='\n'){
printf("The number apeared %i times\n",total);
exit(0);
}
if(array[count]==number){
total+=1;
++count;
}
else{
++count;
}
}
}