This is a memcpy inquiry.

Asked 2 years ago, Updated 2 years ago, 88 views

It is a program that receives two people from a file, checks each of them, and prints them out to the file.

Class | Read files with name structure one line at a time.

With the class number information of number 1, 0 to 100 information is inquired by inquiring the query.

The previous class number and name are information read from the file (must be printed as read) + output the result information read from the query.

Class | Name | Department | Education Name | Professor in Charge | Class Start Date | Class End Date |

But the one with the least number 2 results comes out well Class | Name | Department | Education Name | Professor in Charge | Class Start Date | Class End Date | But... The 2nd result is a lot of class and name are not available.

(blank)|(blank)|Department|Education name|Professor in charge|Start date of class|End date of class|

Why is it coming out like this?

The reading part is

fgets( buf, size, fp) != 0){
 memset (readData, 0x00, sizeof(readData)); 
 memcpy (readData, buf, strlen(readData)-1));
}

ReadData is the school class | name part. But it comes out well, but it comes out, and then some comes out, and then it comes out.

c unix

2022-09-20 21:28

1 Answers

If you upload the entire code, it will be easier for others to answer.

code on the question first.
fgets( buf, size, fp) != 0){ memset (readData, 0x00, sizeof(readData)); memcpy (readData, buf, strlen(readData)-1)); }

From

The third argument of the memcpy function is invalid. memcpy (readData, buf, strlen(readData)-1)); memcpy (readData, buf, strlen(buf))); must be corrected.

I don't think you're making any exceptions. According to the current code, the size variable must be very large to contain one line of the text file. If a line in a text file is very long, it can be a bug. Also, the readData space must be larger than strlen(buf)+1 to operate properly.


2022-09-20 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.