0

How can I pass a whole array named arrayt of type structure named task to a function called create_task?

We need to define the data type of arrayt while passing it to a function. What would be its data type? task, struct task or struct?

#include<stdio.h>
#include <string.h>

// problem: HOW TO PASS AN ARRAY IN A FUNCTION OF TYPE STRUCT
void create_task(struct task arrayt );

struct task{
    char t_name[99];
    char task_noted[999];
};

int main()
{
    struct task arrayt[999];
    int check=0;
    while(check>3||check<1){
        printf("Enter 1 to create a task\nEnter 2 to delete a task\nEnter 3 to view task:\n");
        scanf("%d",&check);
    }

    switch(check){
        case 1:
            printf("CREATING A TASK\n");
            create_task(arrayt);
            break;
        case 2:
            printf("DELETE TASK");
            break;
        case 3:
            printf("VEIW TASKS");
            break;
        default :
            printf("INVALID OPTION!!!!");
            break;
    }
}

void create_task(struct task arrayt ){
    char name ;
    printf("Enter Task Name: ");
    scanf(" %s ",&name);
    FILE *ptr;
    ptr = fopen("data.txt","a");
    
    fclose(ptr);
}
a2800276
  • 3,272
  • 22
  • 33

1 Answers1

0
#include<stdio.h>
#include <string.h>

struct task{
char t_name[99];
char task_noted[999];
};

void create_task(struct task arrayt[] ); // Function prototype after structure declaration    

int main(){

struct task arrayt[999];
int check=0;
while(check>3||check<1){
    printf("Enter 1 to create a task\nEnter 2 to delete a task\nEnter 3 to veiw task:\n");
    scanf("%d",&check);
}

switch(check){
    case 1:
        printf("CREATING A TASK\n");
        create_task(arrayt);
        break;
    case 2:
        printf("DELETE TASK");
        break;
    case 3:
        printf("VEIW TASKS");
        break;
    default :
        printf("INVALID OPTION!!!!");
        break;
}
}
void create_task(struct task arrayt[] ){
char name[50]; // defined an array
printf("Enter Task Name: ");
scanf(" %s",name);  // No need of &

// Do whaterever required here.
}
Krishna Kanth Yenumula
  • 2,533
  • 2
  • 14
  • 26