Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 50
- void arrayOfChars(){
- printf("Введите размер массива\n");
- int size = 0;
- char buf2[1024];
- fgets(buf2, 1024, stdin);
- size = atoi(buf2);
- // scanf("%d", &size);
- char *p = (char *) malloc(size * sizeof(char));
- printf("Динамический массив создан\n");
- for (int i = 0; i< size; i++){
- printf("I = %d\n", i);
- char buf[MAX];
- int lim = 0;
- printf("Введите строку: ");
- fgets(buf, MAX, stdin);
- printf("string is: %s\n", buf);
- for (int i = 0; i < MAX; i++)
- {
- if (buf[i] == '\n'){
- lim = i;
- break;
- }
- }
- printf("%d\n",lim);
- char line[lim];
- for (int i = 0; i < lim; i++){
- line[i] = buf[i];
- }
- printf("line = %s\n", line);
- p[i] = *(char *) malloc(lim + 1 * sizeof(char));
- strcpy(&p[i], line);
- printf("%s\n", &p[i]);
- }
- for (int i = 0; i < size; i++){
- printf("%s\n", p[i]);
- }
- }
- int main(){
- arrayOfChars();
- }
Advertisement
Add Comment
Please, Sign In to add comment