#include <stdio.h>
#include <string.h>
#include <malloc.h>
char **logFileSelection(int *len){
char ** arr = malloc(10 * sizeof(char *));
char *month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int i, j = 0;
for(i = 0; i < 12; i++){
arr[j] = malloc(50 * sizeof(char));
arr[j] = month[i];
j++;
*len = *len+1;
}
return arr;
}
int main(){
int len = 0;
char **arr = logFileSelection(&len);
printf("length: %d\n", len);
int i;
for(i = 0; i < len; i++){
printf("%s\n", arr[i]);
}
return 0;
}
#include <string.h>
#include <malloc.h>
char **logFileSelection(int *len){
char ** arr = malloc(10 * sizeof(char *));
char *month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int i, j = 0;
for(i = 0; i < 12; i++){
arr[j] = malloc(50 * sizeof(char));
arr[j] = month[i];
j++;
*len = *len+1;
}
return arr;
}
int main(){
int len = 0;
char **arr = logFileSelection(&len);
printf("length: %d\n", len);
int i;
for(i = 0; i < len; i++){
printf("%s\n", arr[i]);
}
return 0;
}
No comments:
Post a Comment