Tag:

用于大输入的数字频率程序

我编写了以下程序,以找出每个数字在字符数组中出现的次数。 int main(){ char s[2000],count,j=0; fgets(s,2000,stdin); for(int i=0;i<=9;i++) { count=0;j=0; while(*(s+j)) { if(isdigit(*(s+j))) { if(i==(*(s+j)-'0')) count++; } j++; } printf("%d ",count); } return 0; } 但它不适合大量投入。 b3n47b5xf13qlx233rg4u2c949i623e34nt5661se06b675utbpy258wz633855846l761d61x340h1vn19w191sj18v2u333556bh6m5uc4u050am05p961dhmpu6iq4667zg9 预期的产出是 5 10 5 12 8 11 15 4 4 6 但我得到的输出是 5 10 5 12 7 11 13 3 4 5 任何人都可以帮助我找到我出错的地方吗?

如何在c中剪切一部分字符串?

我正在试图弄清楚如何在C中切割一部分字符串。例如,你有这个字符串“狗因为一辆车在过马路时撞到了他而死了”一个函数如何制作句子“a过马路时撞到了他的车“或”一辆车撞到了他“ 你如何使用C的库(或/和)自定义函数来解决这个问题? 好吧,我没有主要代码,但这将是这个实验的结构 #include #include #include #include #include #include #include “display_usage.c”/*If the user enters wrong arguments it will tell them how it should be */ void cut( const char *file, int option, int first, int last ); int main(int argc, char *argv[] ) { FILE *fp; char ch; fp = fopen(“test.txt”, “r”); // Open file […]