创建了一个含有字符串数组的结构体,然后在函数的调用时使用的是指针变量,但在使用gets()函数时一直报错:将一个无效参数传递给了将无效参数视为严重错误的函数。在函数编译的时候没有报错,但一直无法运行,想问问各位大佬这是什么问题
完整代码如下:
#define _CRT_SECURE_NO_WARNINGS 1
#define MAXSIZE 100
#include<stdio.h>
#include <string.h>
typedef struct
{
char word[MAXSIZE];
int length;
}sentence;
sentence old, new;
struct sentence* change(sentence* p1,sentence* p2)
{
char stop = '$'; //定义截止标志
int i,j;
printf("请输入字符串:\n");
for (i = 0; ; i++)
{
gets(p1->word[i]);
if (strcmp(p1->word[i],'a') == 0) //检测到输入值为截止标志
{
p1->length = i-1;
break; //结束赋值
}
}
printf("输入字符串为:");
for (i = 0; i < p1->length; i++)
printf("%s", p1->word[i]);
//将原字符串倒序赋值到新字符串中
j = 0;
for (i = p1->length; i >0; i--)
{
for (i; i > 0; i--)
{
if (p1->word[i] = ' ')
{
if (p1->word[i - 1] = ' ')
{
break;
}
else
{
p2->word[j] = p1->word[i];
j++;
}
}
else
{
p2->word[j] = p1->word[i];
j++;
}
}
}
p2->length = j;
printf("输出字符串为:");
for (j = 0; j < p2->length; j++)
{
printf("%s", p2->word[j]);
}
return p2;
}
int main()
{
change(&old,&new);
return 0;
}