使用的是DEVC++環境
#include <stdio.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
char *elem;
int length;
int listsize;
}Sqlist;
void InitList_Sq(Sqlist *L) //構造一個空線性表
{
L->elem=(char*)malloc(LIST_INIT_SIZE*sizeof(char));
if(!L->elem)
{
printf("ERROR!");
exit(1);
}
L->length=0;
L->listsize=LIST_INIT_SIZE;
}
void inversion(Sqlist *L)
{
char *p,*q,t=0;
p=L->elem;
q=L->elem+L->length-1;
while(p<q)
{
t=*p;
*p=*q;
*q=t;
}
}
int main()
{
Sqlist *L;
int i=0;
char c;
InitList_Sq(L);
do{
printf("請輸入一個字母('/'退出回圈):\n");
scanf("%c",&c);
if((L->length+1)>L->listsize) //順序表已滿,重新分配空間
{
L->elem=(char*)realloc(L->elem,(LIST_INIT_SIZE+LISTINCREMENT)*sizeof(char));
if(!L->elem)
{
printf("ERROR!");
exit(1);
}
L->length=i;
L->listsize=LIST_INIT_SIZE+LISTINCREMENT;
}
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||c=='/')
{
*(L->elem+i)=c;
i++;
L->length=i;
}
else printf("輸入錯誤!請輸入字母!\n");
}while(c!='/');
if(L->length==0) printf("\n未輸入元素,無法逆置");
else if(L->length==1) printf("\n只有一個元素%c,無法逆置",*(L->elem));
else{
inversion(L);
printf("元素逆置為:\n");
for(i=0;i<L->length;i++)
printf("%c ",*(L->elem+i));
}
}

程式無法運行。求幫忙修改!!看看哪里出了問題。十分感謝!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/234076.html
標籤:C語言
上一篇:C語言—順序元素的逆置,回圈部分出了點問題,求幫助!!詳細在下面說明。
下一篇:C語言已知兩個陣列:int x[4] = { 1,1,1,1}; int h[6] = {6,5,4,3,2,1}。對這兩個陣列做以下運算
