Question
Need the code is c Hello Im getting an error in visual studio, from line 29 pic bellow. attached are all of the data and
Need the code is c
Hello Im getting an error in visual studio, from line 29 pic bellow. attached are all of the data and stuff below. Im also having trouble with the make file which is necessary, the make file needs to run the program later and I would appreciate if you can show me how that is set up Im really new to C so any help would be great with this.
Here is my code as well as everything needed.
ABC123Project0.c
#include #include #include #include "Project0.h"
#define FILENAME "Project0Input.txt"
// main function int main() { // File descriptor FILE* fd; char word[12]; // stores each word in file int i = 0, num_emp = 0; // iterator
// Open file fd = fopen(FILENAME, "r");
// If file does not exists print error if (fd == NULL) printf("Can't open %s for reading. ", FILENAME); else { // Read the first line to get number of employees fscanf(fd, "%s", word); num_emp = atoi(word);
// Declaring an Employee array to store data of employees Employee employees[num_emp];// This is the line with the problem
// Read input from a and store one line at a time while (fscanf(fd, "%s", word) != EOF) { strcpy(employees[i].name, word);
// scan ID fscanf(fd, "%s", word); employees[i].ID = atoi(word);
// scan Hourly rate fscanf(fd, "%s", word); employees[i].hourly_rate = atof(word);
i++; } // Close file fclose(fd);
// Print the data stored for (i = 0; i
Project0.h
#pragma once
// structure to store employee data struct EmployeeData { char name[10]; int ID; double hourly_rate; }; typedef struct EmployeeData Employee;
Project0Input.txt
28 Anima 460011 15.20 Anita 389430 13.88 Arya 386882 12.00 Asa 148350 15.80 Asha 659282 16.08 Azami 535045 11.86 Basia 355509 10.17 Baz 994370 13.84 Caris 686199 17.52 Duska 358274 17.97 Evander 956796 15.76 Haris 203182 16.32 Idris 365037 10.22 Kala 841984 15.74 Kamal 528840 18.44 Ken 814975 19.77 Kim 833572 16.32 Laila 377438 17.29 Lina 731865 11.21 Lulu 680533 18.39 Malik 246738 14.74 Nia 152609 11.89 Noor 335931 17.54 Paz 461431 16.32 Raisa 557325 11.59 Samir 377626 18.99 Talia 833657 16.58 Zahara 444636 18.48
MakeFile
# Define the machine object files for your program OBJECTS = abc123Project0.o # Define your include file INCLUDES = Project0.h
# make for the executable project0: ${OBJECTS} gcc -g -o project0 ${OBJECTS}
# Simple suffix rules for the .o %.o: %.c ${INCLUDES} gcc -g -c $
# Clean the .o files clean: rm -f ${OBJECTS}
In this project we will maintain an array that contains information about a list of employees. The main purpose of this project is to serve as a basic C-review as well as show you how the inputs for our projects will be formatted (reading from a file where each line of the file contains one "input" or "command"). Note that we give you a sample input file to work with and test your code, but your code should be written generally enough to handle other input files that have the same formatting (different number of employees, different names, etc.). Files provided in the project: 1) Projecto.h. The file now only contains a comment. You need to an Employee struct in this file. The struct should contain 3 variables. a. A C-string for the name. You can assume that no name is more than 9 characters long, so this can be a character array of size 10 (to account for the null character). b. An integer for the ID. Each ID is a 6-digit number. c. A double for the Employee's hourly rate. 2) abc123Projecto.c. Rename this file to your abc123. This file includes Projecto.h, stdlib.h, and stdio.h contains a main() function with comments for what you need to implement. 3) Makefile. Update the makefile to reflect your abc123. You can implement your code however you like, however before submitting ensure your project compiles on the fox servers using this makefile. If it does not compile using the makefile then you will get 0 points! You can compile using the command make and you can execute your program using./projecto. 4) ProjectOinput.txt. The first line of the file denotes the number of employees. In the sample input this number is 28. Each employee's information is listed on a single line in the following format: "name ID_HourlyRate". Again, when we test your code we will be using a different file than this one, but it will still be in this same format. abe E0028 abc123Projecto.c 29 X C2057 abc123ProjectO.c 29 expression must have a constant Final Attempt value expected constant expression Final Attempt cannot allocate an array of constant Final Attempt size 0 'employees': Final Attempt unknown size X C2466 abc123ProjectO. 29 X C2133 abc123Projecto.c 29 In this project we will maintain an array that contains information about a list of employees. The main purpose of this project is to serve as a basic C-review as well as show you how the inputs for our projects will be formatted (reading from a file where each line of the file contains one "input" or "command"). Note that we give you a sample input file to work with and test your code, but your code should be written generally enough to handle other input files that have the same formatting (different number of employees, different names, etc.). Files provided in the project: 1) Projecto.h. The file now only contains a comment. You need to an Employee struct in this file. The struct should contain 3 variables. a. A C-string for the name. You can assume that no name is more than 9 characters long, so this can be a character array of size 10 (to account for the null character). b. An integer for the ID. Each ID is a 6-digit number. c. A double for the Employee's hourly rate. 2) abc123Projecto.c. Rename this file to your abc123. This file includes Projecto.h, stdlib.h, and stdio.h contains a main() function with comments for what you need to implement. 3) Makefile. Update the makefile to reflect your abc123. You can implement your code however you like, however before submitting ensure your project compiles on the fox servers using this makefile. If it does not compile using the makefile then you will get 0 points! You can compile using the command make and you can execute your program using./projecto. 4) ProjectOinput.txt. The first line of the file denotes the number of employees. In the sample input this number is 28. Each employee's information is listed on a single line in the following format: "name ID_HourlyRate". Again, when we test your code we will be using a different file than this one, but it will still be in this same format. abe E0028 abc123Projecto.c 29 X C2057 abc123ProjectO.c 29 expression must have a constant Final Attempt value expected constant expression Final Attempt cannot allocate an array of constant Final Attempt size 0 'employees': Final Attempt unknown size X C2466 abc123ProjectO. 29 X C2133 abc123Projecto.c 29Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started