c - Duplicating strchr() -
i pretty new c, taking introductory course, , having issues homework problem. goal of program pass array name of type string , dynamically chosen character loop function. function must check string chosen character , if found return pointer character in string. if character not found null pointer supposed returned. code gets stuck in infinite loop on first character of string...
#include<stdio.h> char occur(char array[],char c); int main(void){ char array[]="hello world!"; int = 33; char c; char occurence; for(i=33;i<=126;i++){ c = i; occurence=occur(array,c); printf("%c\n",occurence); } return 0; } char occur(char array[], char c){ int = 0; char *temp=array; for(temp=array+i;*temp!='\0';i++){ if(c==array[i]){ return *temp; } else{} } return 0; }
use
for(temp=array; *temp!='\0'; temp++){ if(c==*temp) { ...
Comments
Post a Comment