Простая программа со строками, но выдает ошибку сегментирования - C (СИ)
Формулировка задачи:
#include<stdio.h>
#include<string.h>
int main(){
char *mas,c;
mas=&mas[0];
while(c=getchar()!='\n'){
*mas=c;
*mas++;
c=getchar();}
puts("your string:");
mas=&mas[0];
while(*mas!='\0')
printf("%s", mas);
*mas++;
}
~Решение задачи: «Простая программа со строками, но выдает ошибку сегментирования»
textual
Листинг программы
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int SIZE = 64;
char *mas = (char *)malloc(sizeof(char) * SIZE);
char *str = mas;
int c;
while((c = getchar()) != '\n') {
*mas = c;
mas++;
}
mas = str;
puts("your string: ");
while(*mas != '\0') {
printf("%c", *mas);
mas++;
}
free(str);
return EXIT_SUCCESS;
}