Skip to content

Instantly share code, notes, and snippets.

@ChlorUpload
Created September 9, 2019 16:13
Show Gist options
  • Save ChlorUpload/ea79511c79be7818ab02ffd3c1f71797 to your computer and use it in GitHub Desktop.
Save ChlorUpload/ea79511c79be7818ab02ffd3c1f71797 to your computer and use it in GitHub Desktop.
double pointer exercise program ( visual studio 2019 )
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned n;
scanf("%u", &n);
char* str = (char*)malloc(sizeof(char) * (n + 1));
scanf_s("%s", str, n + 1);
char** arrs = (char**)malloc(sizeof(char*) * (n + 1));
for (int i = 0; i <= n; ++i)
{
arrs[i] = (char*)malloc(sizeof(char) * (i + 1));
arrs[i][i] = '\0';
for (int j = 0; j < i; ++j)
arrs[i][j] = str[j];
}
for (int i = 0; i <= n; ++i)
{
printf("%s\n", arrs[i]);
}
for (int i = 0; i <= n; ++i)
free(arrs[i]);
free(arrs);
free(str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment