1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main() 5 { 6 int readi(); 7 char* readc(); 8 void write(char* read,int i); 9 10 int i=0; 11 char* read001=readc(); 12 i=readi(); 13 printf("%s\n",read001); 14 write(read001,i); 15 if((getchar())==‘\n‘) 16 getchar(); 17 } 18 int readi(){ 19 int i=0; 20 printf("输入i"); 21 scanf("%d",&i); 22 return(i); 23 } 24 char* readc(){ 25 int a=0,b=10,c=1; 26 printf("输入字符"); 27 char* read001=(char*)malloc(10*sizeof(char)); 28 while(c){ 29 read001[a]=getchar(); 30 if(a==b-1){ 31 char* read002=read001; 32 b=b+10; 33 char* read001=(char*)malloc(b*sizeof(char)); 34 for(int k=0;k<b-11;k++){ 35 read001[k]=read002[k]; 36 } 37 } 38 if(read001[a]==‘\n‘) 39 c=0; 40 a=a+1; 41 } 42 read001[a-1] = ‘\0‘; 43 return read001; 44 } 45 void write(char* read,int i){ 46 char* write=(char*)malloc(i*sizeof(char)); 47 static int a=0; 48 for(;a<i+1;a++){ 49 if(read[a]==‘\0‘){ 50 break; 51 } 52 write[a]=read[a]; 53 } 54 for(;a<i+1;a++){ 55 write[a]=‘m‘; 56 } 57 write[a-1]=‘\0‘; 58 printf("%s",write); 59 }
时间: 2024-10-26 13:13:17