0
它的功課,對不起。 我不能讓工作計劃在單詞統計字符,對於一個例子:計算選定字的字符數
- 我輸入字符串:我的名字是彼得
- 程序會詢問哪個詞來處理..
- 我進入數量:3
- 計劃署說:第三字數爲2
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char text[200],vards[20];
int i, length,lengthv, count=0,x;
printf("insert txt\n");
gets(text);
length=strlen(text);
for(i=0; i<length; i++)
{
if(text[i]!=' ' && text[i]!='.' && text[i]!=',')
{
printf("%c", text[i]);
if (text[i+1]=='\0')
count++;
}
else
{
if(text[i-1]!=' ' && text[i-1]!='.' && text[i-1]!=',')
{
count++;
printf("\n");
}
}
}
printf("detect lenght of wich name\n");
for(i=0;i<x;i++);
scanf("%s", &text);
lengthv=strlen(vards);
printf("\n The lenght of name is %d", lengthv);
getch();
return 0;
}
請在發佈前正確地縮進代碼。此外,請描述代碼在實踐中打印的內容,而不是僅僅說「不起作用」。 –
而這段代碼並不是你想要的。 –
你真正的問題是什麼?對於輸入名稱:peter,如果輸入編號爲2,則輸出必須爲2,對於輸入編號3,輸出必須爲1。你的意思是一個字符在一個字符串中出現的次數? – niko