嘿,夥計們,我在這個程序中遇到了一些麻煩。我覺得我有差不多吧,除了它打印垃圾到屏幕:(C Progamming-輸入3個字符並按相反順序打印
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define strsize 30
typedef struct member
{
int number;
char fname[strsize];
struct member *next;
} RECORD;
RECORD* insert (RECORD *it);
RECORD* print(RECORD *it, int j);
int main (void)
{
int i, result;
RECORD *head, *p;
head=NULL;
printf("Enter the number of characters: ");
scanf("%d", &result);
for (i=1; i<=result; i++)
head=insert (head);
print (head, result);
return 0;
}
RECORD* insert (RECORD *it)
{
RECORD *cur, *q;
int num;
char junk;
char first[strsize];
printf("Enter a character:");
scanf("%c", &first);
cur=(RECORD *) malloc(sizeof(RECORD));
strcpy(cur->fname, first);
cur->next=NULL;
if (it==NULL)
it=cur;
else
{
q=it;
while (q->next!=NULL)
q=q->next;
q->next=cur;
}
return (it);
}
RECORD* print(RECORD *it, int j)
{
RECORD *cur;
cur=it;
int i;
for(i=1;i<=j;i++)
{
printf("%c \n", cur->fname);
cur=cur->next;
}
return;
}
幫助表示讚賞的事實!謝謝
爲什麼不給我們一點關於你想要完成什麼的更多細節,而不是將所有的代碼轉儲到我們的頂端,期待我們爲你調試?並且爲了將來的參考,您可能希望獲取正確的語言名稱。 – Marlon 2011-06-02 01:17:17
我的不好,它是C.它應該提示用戶輸入3個字符並按相反順序輸出3個字符到屏幕 – James 2011-06-02 01:21:34
並且它應該用鏈表來解決,對不對?爲什麼你會用它們呢?它很容易就像「char a,b,c; cin >> a >> b >> c; cout << c << b << a」。 – SinistraD 2011-06-02 01:23:42