c语言求帮忙debug!
  • 板块学术版
  • 楼主lluosi
  • 当前回复6
  • 已保存回复6
  • 发布时间2020/12/1 23:17
  • 上次更新2023/11/5 06:55:27
查看原帖
c语言求帮忙debug!
400091
lluosi楼主2020/12/1 23:17
#include <string.h>
#include <stdio.h>
char op[3];
char a[105] = {0}, b[105] = {0};
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		memset(op, 0, sizeof(op));memset(a, 0, sizeof(a));
		int n, i, j, k;
		scanf("%s", op);
		getchar();
		if (strcmp(op, "len") == 0) {
			gets(a);
			printf("%d\n", strlen(a));
		}
		else if (strcmp(op, "cmp") == 0)
		{
			scanf("%s", a);
			scanf("%s", b);
			if (strcmp(a, b) == 0) printf("=\n");
			else if (strcmp(a, b) < 0) printf("<\n");
			else printf(">\n");
		}
		else if (strcmp(op, "cat") == 0)
		{
			scanf("%s", a);
			scanf("%s", b);
			scanf("%d", &n);
			strncat(a, b, n);
			printf("%s\n", a);
		}
	}
	return 0;
}

感觉问题可能出在a数组的清空上? 并求怎么debug(不能加行加分号只能改一行)

2020/12/1 23:17
加载中...