C语言编程:从键盘输入一个字符串,分别显示字符串的每个字符及其对应的ASCII码。

拜托各位帮帮我呀

第1个回答  2009-05-30
#include <stdio.h>
struct text
{
char c;
struct text *next;
};
void main()
{
text *head = new text;
text *current = head;
text *next = NULL;
char c;
while(1)
{
if((current->c = getchar()) == '\n')
break;
//printf("%c:%d\n", current->c, current->c);
next = new text;
current->next = next;
current = current->next;
}
current->next = NULL;
current = head;
while(current->c != '\n')
{
printf("%c:%2x\n", current->c, current->c);
current = current->next;
}
}
//无论多么长字符串均可以本回答被提问者采纳
第2个回答  2009-05-30
先定义一个数组(尽量大如:a[10000])i,n=0;
用for循环输入字符串
for(i=0;;i++)
{ scanf("%c",&a[i]);n++;
if(a[i]==‘\0’) break;}
输出也可也用for或while。
for(i=0;i<n;n++)
printf(“%c\n”,a[i]);
for(i=0;i<n;n++)
printf("%d\n",a[i]);

我建议你多看看书!