Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- gcc std=c99 -Wall -o main main.c
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_LEN 1024
- void readString(char *buf){
- fgets(buf, MAX_LEN, stdin);
- }
- void readStrings(char buf[][MAX_LEN], int count){
- for (int i = 0; i < count ; i++){
- readString(buf[i]);
- }
- }
- void printSrings(char buf[][MAX_LEN], int count){
- for (int i = 0; i < count ; i++){
- printf("%s", buf[i]);
- }
- }
- void readStringsDyn(char **buf, int count){
- char buffer[MAX_LEN];
- for (int i = 0; i < count ; i++){
- readString(buffer);
- buf[i] = (char *)malloc(sizeof(char)*strlen(buffer));
- strcpy(buf[i], buffer);
- }
- }
- void printSringsDyn(char **buf, int count){
- for (int i = 0; i < count ; i++){
- printf("%s", buf[i]);
- }
- }
- int main(int argc, char **argv){
- int count = 3;
- scanf("%d\n", &count);
- char mas[count][MAX_LEN];//c99 или выше стандарт
- readStrings(mas, count);
- printSrings(mas, count);
- char **masDyn;
- masDyn = (char **)malloc(sizeof(char *)*count);
- readStringsDyn(masDyn, count);
- printSringsDyn(masDyn, count);
- for (int i = 0; i < count; i++)
- {
- free(masDyn[i]);
- }
- free(masDyn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement