4楼讲理论,9楼讲实践,左三圈右三圈动动手再问嘛
梦想拥有一台龙芯3A-4000
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<stddef.h> //#define BUFFER_LEN 128 #define NUM_P 100 const size_t BUFFER_LEN=128; //const size_t NUM_P=100; //为什么改成define申明就可以,两个应该是一个意思啊??? int main(void) { char buffer[BUFFER_LEN]; char *pS[NUM_P]={NULL}; char *pbuffer=buffer; int i=0; printf("\nYou can enter up to %u message each up to %u characters",NUM_P,BUFFER_LEN-1); for(i=0;i<NUM_P;i++) { pbuffer=buffer; printf("\nEnter %s message,or press Enter to end\n",i>0?"another":"a"); while((pbuffer-buffer<BUFFER_LEN-1)&&((*pbuffer++=getchar())!='\n')); if((pbuffer-buffer)<2) break; if((pbuffer-buffer)==BUFFER_LEN && *(pbuffer-1)!='\n') { printf("String too long -maximum %d characters allowed.",BUFFER_LEN); i--; continue; } *(pbuffer-1)='\0'; pS[i]=(char*)malloc(pbuffer-buffer); if(pS[i]==NULL) { printf("\nOut of menory - ending program."); return 1; } strcpy(pS[i],buffer); } printf("\nIn reverse order,the strings you entered are:\n"); while(--i >=0) { printf("\n%s",pS[i]); free(pS[i]); pS[i]=NULL; } system("pause"); return 0; }
int a[5] = {0}; char str[] = "aaa";
#define N 5 ... int a[N] = {0};
#include <stdio.h> #include <memory.h> int main(void) { const size_t a = 9; int right[a]; // int wrong[a] = {0}; memset(right, 0, a * sizeof(int)); return 0; }