#include<stdio.h> sub(char a,int t1,int t2) { char ch; while(t1<t2) { ch=(a+t1); (a+t1)=(a+t2); *(a+t2)=ch; t1++; t2--; } } int main() { char s[12]; int i; for(i=0;i<12;i++) s[i]='A'+i+32; sub(s,7,11); for(i=0;i<12;i++) printf("%c",s[i]); printf("\n"); return 0; } 运行结果
时间: 2023-06-23 12:46:44 浏览: 77
这段代码存在严重的语法错误,无法编译通过。首先,函数sub的参数a应该是一个字符数组,而不是一个字符;其次,在函数中使用指针操作时,需要使用指针符号 *,而不是括号。此外,程序中没有声明函数sub的返回类型,应该显式声明为void。以下是修正后的代码:
```
#include <stdio.h>
void sub(char *a, int t1, int t2) {
char ch;
while(t1 < t2) {
ch = *(a+t1);
*(a+t1) = *(a+t2);
*(a+t2) = ch;
t1++;
t2--;
}
}
int main() {
char s[12];
int i;
for(i = 0; i < 12; i++)
s[i] = 'A' + i + 32;
sub(s, 7, 11);
for(i = 0; i < 12; i++)
printf("%c", s[i]);
printf("\n");
return 0;
}
```
运行结果为:
```
ABCDEFGHgfedCBA
```
相关问题
include <stdio.h>#include <stdlib.h>
这是一个C语言的标准头文件的引用,其中<stdio.h>包含了C语言的输入输出函数,而<stdlib.h>包含了一些通用的工具函数和内存分配函数。这些头文件在C语言中非常常见,几乎每个C程序都会用到它们。下面是一个简单的例子,展示了如何使用这两个头文件。
```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
char str[100];
printf("Enter an integer: ");
scanf("%d", &num);
printf("You entered %d.\n", num);
printf("Enter a string: ");
scanf("%s", str);
printf("You entered %s.\n", str);
return 0;
}
```
上面的程序使用了<stdio.h>中的printf和scanf函数,以及<stdlib.h>中的exit函数。输入一个整数和一个字符串,然后将它们输出到控制台上。
#include <stdio.h> #include <malloc.h> typedef char ElemType; typedef struct LNode
#include <stdio.h> 和 #include <malloc.h> 是 C 语言中的头文件,前者用于输入输出,后者用于内存动态分配和释放。
typedef char ElemType; 定义了一个名为 ElemType 的数据类型,实际上是 char 类型。
typedef struct LNode 定义了一个名为 LNode 的结构体类型。
该结构体类型中可以包含多个成员变量,具体定义方式如下:
typedef struct LNode {
int data;
struct LNode* next;
} LNode;
这里定义了一个 LNode 结构体类型,其中包含两个成员变量:data 和 next。data 是一个整型变量,next 是一个指向 LNode 类型的指针变量。这种结构体类型通常用于链表的实现。
相关推荐
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)