From what i've read so far I think I can use the one file pointer I have to read from and write to the file if I use the "r+b" argument in my fopen function.

It shouldn't be hard for me to add something to the program that would let the user rename each string, but I don't know how i would go about writing the changed strings back to the file. Any help would be appreciated.

I am also having an issue with the year string. It is 4 bytes long and when i try to print my year string it prints the 4 character long year string, plus the album string next to it (which is why I added the " year[4] = '\0' ; " code. I'm guessing the fread function doesn't add the \0 character to the end of the string?

This isn't something that I've done my self before, but to write the data back to the file I think that you need to open the file with r+b like you said and then use fseek() to get to the part that you want to start writing and then use fwrite() to write the new data to the file.

I'm not sure what you mean when you say that it prints the album string next to the year, but I wouldn't do anything to year[4] , since year is only 4 elements long and year[4] is the element after the last element of year . I would make year 5 elements long if and get the first 4 from the file and add the final \0 manually.

Oh dude :icon_frown: There's no year[4] , you're corrupting memory.
Also fseek(fp, 0, SEEK_CUR); is meaningless. printf("Title: "); puts(title); is stupid, when there's printf("Title: %s\n", title); but apparently it failed cause you don't know about C-strings. You don't know about arrays. You don't know Stream I/O, how file pointers behave after read/write. You don't know C.
You cannot develop programs by second guessing what the statements you type perform.
Honestly, why do you guys insist on using C?

Comments

WaltP:Lighten up. Some people aren't geniuses like you that know this stuff instinctually. They actually need to LEARN and make mistakes

Oh dude :icon_frown: There's no year[4] , you're corrupting memory.
Also fseek(fp, 0, SEEK_CUR); is meaningless. printf("Title: "); puts(title); is stupid, when there's printf("Title: %s\n", title); but apparently it failed cause you don't know about C-strings. You don't know about arrays. You don't know Stream I/O, how file pointers behave after read/write. You don't know C.
You cannot develop programs by second guessing what the statements you type perform.
Honestly, why do you guys insist on using C?

Er, this is all a bit unfair, and not particularly constructive! If you don't want to help, then don't. But this is a forum, where people who don't know the answers to question can ask for help.

Oh dude :icon_frown: There's no year[4] , you're corrupting memory.
Also fseek(fp, 0, SEEK_CUR); is meaningless. printf("Title: "); puts(title); is stupid, when there's printf("Title: %s\n", title); but apparently it failed cause you don't know about C-strings. You don't know about arrays. You don't know Stream I/O, how file pointers behave after read/write. You don't know C.
You cannot develop programs by second guessing what the statements you type perform.
Honestly, why do you guys insist on using C?

I take it you're a linux user..

I only added the write to year[4] because it was printing the year string wrong without it, and my statement seemed to put the null character in the right spot despite element 4 not being declared. I know how arrays work (an array with 4 elements has element 0-3...). I'm still learning stream I/O and some more in depth stuff about file pointers. I just figured getting some answers from people about specific questions would speed up my learning process.

I don't understand why the year string would print any different from the others. The only difference is the length (4 characters instead of 30). Could the fact that it contains numbers instead of letters possibly have something to do with it?

The only problem with your year string is that it doesn't have a terminating null. It's not stored in the file as a C string, but rather as a set of four characters. The same goes for your other strings, but you are fortunate enough that they happen to be filled with nulls.

You can change the printf statements to use %c conversion instead of %s, or you can make the strings you read in one character wider and explicitly initialize them all to nulls. Since the final NULL never gets written, they will always be properly terminated.

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...