一个小问题,怎么让这个程序不以读入换行符结束,而是以EOF结尾
#include <stdio.h>#include <stdlib.h>
typedef struct String String;
struct String
{
char ch;
String *next;
};
void SaveSring(String ** head);
void PrintString(String *head);
void SaveToArray(String *head);
int main(void)
{
String *head = NULL;
printf("Please input a string\n");
SaveSring(&head);
PrintString(head);
SaveToArray(head);
return 0;
}
void SaveSring(String ** head)
{
String *current = NULL;
String *previous = NULL;
while(1)
{
current = (String*)malloc(sizeof(String));
if (*head == NULL)
{
*head = current;
}
if (previous != NULL)
previous->next = current;
previous = current;
current->next = NULL;
scanf("%c", ¤t->ch);
if (current->ch =='\n')
{
current->ch = '\0';
current->next = NULL;
break;
}
}
}
void PrintString(String *head)
{
while (head != NULL)
{
printf("%c",head->ch);
head = head->next;
}
printf("\n");
printf("\n");
printf("\n");
}
void SaveToArray(String *head)
{
int cnt;
String *temp = head;
for(cnt = 1; temp->next != NULL;)
{
temp = temp->next;
cnt=cnt+1;
}
char string[100];
for (int i = 0;i<cnt;++i)
{
string[i] = head->ch;
head = head->next;
}
puts(string);
printf("\n");
}
怎么让这个程序不以读入换行符结束,而是以EOF结尾