Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is about C Programming. Q. Implement a function get_numbers and call it in the main function. The function should read one line of the

This is about C Programming.

Q.

Implement a function get_numbers and call it in the main function. The function should read one line of the file which includes integers, and return an integer pointer for the integers.

- do not assume the length of array. -read one number and use it to allocate memory space in get_numbers. -free the memory space in the main function

I wrote some codes for the question, but it doesn't work proplerly...

please fix my code to make it work properly.

#include #include

int *get_numbers(char filename[],int* line);

int main() { int i =0; int *linep = NULL; int numArr[] = {0};

linep = get_numbers("hw4_2_input.txt",linep); while(linep[i]!=" "){ numArr[i] = linep[i]; if(linep == " "){ putchar(" "); }else{ printf("%d ", numArr[i]); } i++; } free(linep); system("PAUSE"); return 0; }

int *get_numbers(char filename[],int* line) { int N = 0; int i = 0;

FILE *data = fopen(filename,"r"); if(data == NULL){ printf("Failed to open file! "); return 0; }

fscanf(data,"%d",&N); line = (int*)malloc((N+1)*sizeof(int)); printf("%d ",N); for(i=0;i

fclose(data); return line; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

More Books

Students also viewed these Databases questions

Question

Understand the aspects of developing a social media plan? LO.1

Answered: 1 week ago

Question

niscer

Answered: 1 week ago

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago