-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertarray.c
41 lines (39 loc) · 1.05 KB
/
insertarray.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *names[3];
int n, count,l;
for (n = 0; n < sizeof(names) / sizeof(names[0]); n++)
{
printf("Enter the names of your friends: ");
names[n] = malloc(100);
scanf("%s", names[n]);
count = n;
if (count >= sizeof(names) / sizeof(names[0]))
{
char *names2[count * 2];
names[3] = names2[count * 2];
for (count = count; count < count * 2; count++)
{
printf("Enter the names of your friends: ");
names2[count] = malloc(100);
scanf("%s", names2[count]);
}
for (l = 0; l < count;)
{
printf("%s\n", names2[l]);
free(names2[l]); // Free the allocated memory
l = l + 1;
}
}
else
{
printf("%s\n", names[l]);
free(names[l]); // Free the allocated memory
l = l + 1;
}
}
return 0;
}