69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
int main()
{
//编译通过,但不能正确运行
int i=0;
char *op;
char c;
while(c=getchar()){
*(op+(i++))=c;
printf("%s\n",op);
i++;
}
printf("%s\n",op);
system("pause");
return 0;
}
#include<stdio.h>
int main()
{
//出现乱码
int i=0;
char *op;
char c;
while(c=getchar()){
*(op+(i++))=c;
printf("%s\n",op);
i++;
}
printf("%s\n",op);
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main() {
int i;
char *op;
char c;
op=(char *)malloc(10 * sizeof(char));//op=malloc(10 * sizeof(char));
if (NULL==op) return 1;
i=0;
while (1) {
c=getchar();
if ('\n'==c) break;
if (EOF==c) break;
op[i] = c;
i++;
if (i>=9) break;
}
op[i] = '\0';//op[i]=0;
printf("%s\n",op);
if(NULL != op) free(op);//free(op);
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main() {
int i;
char *op;
char c;
op=malloc(10 * sizeof(char));
if (NULL==op) return 1;
i=0;
while (1) {
c=getchar();
if ('\n'==c) break;
if (EOF==c) break;
op[i] = c;
i++;
if (i>=9) break;
}
op[i] = '\0';//op[i]=0;
printf("%s\n",op);
if(NULL != op) free(op);//free(op);
system("pause");
return 0;
}
#include <stdio.h>
#include <malloc.h>
int main() {
int i;
char *op;
char c;
op=malloc(10 * sizeof(char));
if (NULL==op) return 1;
i=0;
while (1) {
c=getchar();
if ('\n'==c) break;
if (EOF==c) break;
op[i] = c;
i++;
if (i>=9) break;
}
op[i]=0;
printf("%s\n",op);
free(op);
system("pause");
return 0;
}
#include<stdio.h>
#include<malloc.h>
int main()
{
int i=0;
char *op=0;
char c;
op = malloc(10 * sizeof(char)); //here
while((c=getchar())!='\n'){
*(op + i ) = c;
//printf("%s\n", op); //此语句 会引起乱码
i++;
}
printf("%s\n",op);
system("pause");
free(op);
return 0;
}