#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; }} //无论多么长字符串均可以
先定义一个数组(尽量大如: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]);我建议你多看看书!