输入数个字符建立字符顺序表,功能有求表长度
时间: 2023-04-07 07:00:42 浏览: 53
这个问题可以回答。要建立字符顺序表,可以使用数组来实现。首先需要输入字符,可以使用 scanf 或者 gets 函数来获取用户输入。然后将输入的字符存储到数组中,可以使用循环来实现。最后,可以使用数组的长度来计算表的长度。
相关问题
c语言代码输入数个字符建立字符顺序表,功能有求表长度
可以回答这个问题。建立字符顺序表的代码如下:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef struct {
char data[MAXSIZE];
int length;
} SqList;
void InitList(SqList *L) {
L->length = 0;
}
void CreateList(SqList *L) {
char c;
printf("请输入字符,以#结束:\n");
scanf("%c", &c);
while (c != '#') {
L->data[L->length] = c;
L->length++;
scanf("%c", &c);
}
}
void PrintList(SqList L) {
int i;
printf("字符顺序表为:\n");
for (i = 0; i < L.length; i++) {
printf("%c ", L.data[i]);
}
printf("\n");
}
int main() {
SqList L;
InitList(&L);
CreateList(&L);
PrintList(L);
printf("表长度为:%d\n", L.length);
return 0;
}
输入数个字符建立字符顺序表,求表长度
可以使用数组来建立字符顺序表,具体实现如下:
char str[] = "hello world";
int len = strlen(str);
char table[len];
for (int i = 0; i < len; i++) {
table[i] = str[i];
}
printf("表长度为:%d", len);
输出结果为:表长度为:11