|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <string.h>
- #include <conio.h>
- #include <stdio.h>
- #include <windows.h>
- #define N 81
- fun(char *s)
- {
- int i,j=0,len=0;
- char *b;
- len=strlen(s);
- for(i=len-1;i>=0;i--)
- {
- b[j++]=s[i];
- }
- b[j]=0;
- for(i=0;b[i];i++)
- {
- s[i]=b[i];
- }
- s[i]=0;
- }
- main()
- { char a[N];
- system("cls");
- printf("Enter a string: ");gets(a);
- printf("The original string is: ");puts(a);
- fun(a);
- printf("\n");
- printf("The string after modified: ");
- puts(a);
- }
复制代码
这个程序是实现字符串逆序,编译没有问题。但是运行不出结果。
然后调试出现了access violationa。
求问各位大神是怎么回事?
1.你的函数都没有加任何类型,这在VC上是无法编译过的
2.char *b;你的b什么都没有指向,也没有分配内存,你就直接在下边使用b的值,这样肯定是会报错的,因为内存中都找不到对应的位置和值,要么改成char b[N];或者用malloc分配内存
|
|