?? test14_3.txt
字號(hào):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DATASIZE 10
typedef struct TAG_mydata{
char thestring[DATASIZE];
int iscontinuing;
struct TAG_mydata *next;
}mydata;
mydata *append(mydata *start,char *input);
void displaydata(mydata *start);
void freedata(mydata *start);
int main(void){
char input[DATASIZE];
mydata *start= NULL;
printf("Enter some data,and press Ctrl+D when done.\n");
while(fgets(input,sizeof(input),stdin)){
start=append(start,input);
}
displaydata(start);
freedata(start);
return 0;
}
mydata *append(mydata *start,char *input){
mydata *cur=start,*prev=NULL,*new;
while(cur){
prev=cur;
cur=cur->next;
}
cur=prev;
new=malloc(sizeof(mydata));
if(!new){
fprintf(stderr, "Couldn’t allocate memory,terminating\n");
exit(255);
}
if(cur){
cur->next=new;
}
else{
start=new;
}
cur=new;
strcpy(cur->thestring,input);
cur->iscontinuing=!(input[strlen(input)-1]== '\n'|| input[strlen(input)-1]== '\r');
cur->next=NULL;
return start;
}
void displaydata(mydata *start){
mydata *cur;
int linecounter=0,structcounter=0;
int newline =1;
cur=start;
while(cur){
if(newline){
printf("Line %d:",++linecounter);
}
structcounter++;
printf("%s",cur->iscontinuing);
cur=cur->next;
}
printf("This data contained %d lines and was stored in %d structs.\n",
linecounter,structcounter);
}
void freedata(mydata *start){
mydata *cur,*next=NULL;
cur=start;
while(cur){
next=cur->next;
free(cur);
cur=next;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -