c语言问题急急急!!!!
下面这个程序我的意思是插入一个字符串,为什么不行?#include<stdio.h>intmain(void){voidinsertstring(charresult[]...
下面这个程序我的意思是插入一个字符串,为什么不行?
#include<stdio.h>
int main (void)
{
void insertstring (char result[], char text[], char cha, int start);
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
printf ("cha ru de zifu:");
gets(b);
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
return 0;
}
int len(char string[])
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char result[], char text[], char cha[], int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+1; text[i-num]!='\0'; i++)
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
错在哪里?谢谢 展开
#include<stdio.h>
int main (void)
{
void insertstring (char result[], char text[], char cha, int start);
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
printf ("cha ru de zifu:");
gets(b);
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
return 0;
}
int len(char string[])
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char result[], char text[], char cha[], int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+1; text[i-num]!='\0'; i++)
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
错在哪里?谢谢 展开
5个回答
展开全部
我改得慢了一点 好久没用c语言了 不过还是发出来吧 个人改了三个地方
给你一些建议哦 细心细心还是细心 程序员可马虎不得
#include<stdio.h>
int main (void) //总觉得这个怪怪的~~
{
void insertstring (char result[], char text[], char cha[], int start);//这个地方你粗心了 cha的中括号没有加
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
printf ("cha ru de zifu:\n");
scanf ("%s", &b);//这里我把gets(b)改成了 scanf函数; 不过发现还是上面几位大侠用getchar()的方法好~~可以参考这里啊http://zhidao.baidu.com/question/44948997.html?si=2
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
return 0;
}
int len(char string[]) //字符串长度
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char result[], char text[], char cha[], int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+num; text[i-num]!='\0'; i++)
//还是你粗心 怎么可能是start+1呢 除非插入的字符串长度总是1 应该是start+num;
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
给你一些建议哦 细心细心还是细心 程序员可马虎不得
#include<stdio.h>
int main (void) //总觉得这个怪怪的~~
{
void insertstring (char result[], char text[], char cha[], int start);//这个地方你粗心了 cha的中括号没有加
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
printf ("cha ru de zifu:\n");
scanf ("%s", &b);//这里我把gets(b)改成了 scanf函数; 不过发现还是上面几位大侠用getchar()的方法好~~可以参考这里啊http://zhidao.baidu.com/question/44948997.html?si=2
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
return 0;
}
int len(char string[]) //字符串长度
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char result[], char text[], char cha[], int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+num; text[i-num]!='\0'; i++)
//还是你粗心 怎么可能是start+1呢 除非插入的字符串长度总是1 应该是start+num;
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/*修改好了:如下*/
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
void insertstring (char result[], char text[], char cha[], int start); /*这里有改动*/
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
getchar(); /*这里有改动*/
printf ("cha ru de zifu:");
gets(b);
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
system("pause");
return 0;
}
int len(char string[])
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char result[], char text[], char cha[], int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+num; text[i-num]!='\0'; i++) /*这里有改动*/
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
void insertstring (char result[], char text[], char cha[], int start); /*这里有改动*/
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
getchar(); /*这里有改动*/
printf ("cha ru de zifu:");
gets(b);
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
system("pause");
return 0;
}
int len(char string[])
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char result[], char text[], char cha[], int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+num; text[i-num]!='\0'; i++) /*这里有改动*/
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我直接给你修改正确了,程序如下:
#include<stdio.h>
int main (void)
{
void insertstring (char *result, char *text, char *cha, int start);
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
printf ("cha ru de zifu:");
getchar();
gets(b);
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
return 0;
}
int len(char *string)
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char *result, char *text, char *cha, int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+num; text[i-num]!='\0'; i++)
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
#include<stdio.h>
int main (void)
{
void insertstring (char *result, char *text, char *cha, int start);
int n;
char a[] = "i love china!";
char b[10];
char result[50];
printf ("Enter place:");
scanf ("%d", &n);
printf ("cha ru de zifu:");
getchar();
gets(b);
insertstring (result, a, b, n);
printf ("%s", result);
printf ("\n");
return 0;
}
int len(char *string)
{
int count=0;
while (string[count]!='\0')
++count;
return count;
}
void insertstring (char *result, char *text, char *cha, int start)/*在字符串text中插入字符串cha*/
{
int len (char string[]);
int i, n=0, num=len(cha);
for (i=0; i<start; i++)
result[i] = text[i];
for (i=start ; i<start+num, cha[n]!='\0' ; i++, n++)
result[i] = cha[n];
for (i=start+num; text[i-num]!='\0'; i++)
result[i] = text[i-num];
result[len(text)+num] = '\0';
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.main函数的第一行函数声明
第三个参数 缺中括号
void insertstring (char result[], char text[], char cha[], int start);
2.insertstring函数内第三个for里i的起始值
for (i=start+num; text[i-num]!='\0'; i++)
result[i] = text[i-num];
第三个参数 缺中括号
void insertstring (char result[], char text[], char cha[], int start);
2.insertstring函数内第三个for里i的起始值
for (i=start+num; text[i-num]!='\0'; i++)
result[i] = text[i-num];
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
补充,在printf ("cha ru de zifu:"); gets(b);这两句中间加getchar();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询