string - Write char[128] array to file in C -


I wrote a program to write a four [128] array in CR to file using the write () function is. My code, though, after writing, I can see that the "testeg" string "d" or "a?" Is there a proper way to write four [] arrays to file this in the TestFile.txt file?

  int main () {four pathfile [MAX_PATHNAME_LEN]; sprintf (pathfile, "testFile.txt"); Int fareccipitator = open (pathfile, o_rrdw | o_appnannnarrat, 0777); int num_segs = 10; Int Mode = 200; Const char * segname = "testeg"; / * * / Four real_assigns [128]; Strcpy (real_segname, segname); Write (filed claims, & amp; num_segs, sizeof (int)); Write (Claimed Claimant, Real_signame, Stellen (Real_assignment)); Printf ("real_summammem length% d \ n", (integer) string (actual_signame)); Write (filed claims, and modes, sums (integer)); Close (filedescriptor); Return 0; }     

... char to write [128] array. .. I can see that the string "testeg" ... ... is a contradictory.

In C, there is an array of a string char followed by '\ 0' and four [128] A fixed 128 char is in length.

writes the code (filed claimant, real_signame, strangel (real_agnum)); , it does not, it is not writing a single string, 7 "code" of "test" followed by a '\ 0' . Instead, it was written just 7 char and none ended '\ 0' . Instead, type 128 char

one could instead of writing (filed claims, real_signname, strlen (real_segname) +1); 7 / code> char and '\ 0' to enter . Or write lengths and then interesting parts of the aarti. Or write the entire 128 char array.

As the @sgg suggests, the result of abnormally char is being filed (need to be identified) filed; Mods, sizeof (int)); and are not part of your unmetminated array.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -