I need to find all suffix starting with a character X. For example, for int suffix (char str [], char c)
when the word is ababcd
and the letter b
it should return:
(我需要找到所有以字符X开头的后缀。例如, for int suffix (char str [], char c)
当单词ababcd
和字母b
都应返回时:)
babcd
bcd
and the number 2.
(和数字2)
This is my code:
(这是我的代码:)
#include <stdio.h>
#include <string.h>
int main()
{
char c;
char str[128];
int counter=0;
printf ("Please enter charachter and a string
");
scanf("%c %s",&c,str);
counter = my_suffix(str,c);
printf("The string has %d suffix
",counter);
return 0;
}
int my_suffix(char str[],char c) {
int counter = 0;
for (int i=0; i < strlen(str); i++)
{
if (str[i] == c)
{ puts(str+i);
counter++;
}
}
return counter;
}
I couldn't find why it's not running,
(我找不到为什么它没有运行,)
Thanks!
(谢谢!)
ask by Nadav Nusbaum translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…