C language, readdir and segmentation fault on running -
This code returns a segmentation fault when I try to run it p> Thank you for your advice if you have an idea to search for it to fix.
It is necessary that the function should be special in readrep (), opendir () and readdir (), but I do not see anything wrong, thanks for helping
Add # & lt; Dirent.h & gt; Sys / types.h & gt; #includes & lt; sys / stat.h & gt; #includes & lt; # Include & lt; Unistd.h & gt; #to & lt include, limits.h & gt; #to & lt include, stdlib.h & gt; #to & lt include, stdio.h & gt; #to & lt include, string.h & gt; #Max 256 Define the file * f; Zero Gorite (four * chimine) {F = FOPAN ("locate.db.tmp", "a +"); Int size = Stellen (chemina); Four straw [max]; Fwrite (& amp; size, sizeof (int), 1, f); Fwrite (str, sizeof (four), size, f); Fclose (f); } Read zero REP (char * str) {struct dirent repStruct; Struct dirent * prepStruct; Structure Stat Statsat; Structure State * Buff; Fond & amp; StructStat; prepStruct = & amp; RepStruct; DIR * d = opendir (str); While ((prepStruct = readdir (d)) = null) {int x; Four * fi = maulok (size (four) * maximum); Fi = (prepStruct-> d_name); X = State (Fi, Fond); Mode_tm Meter = structStat.st_mode; Int test; Test = S_ISREG (M); If (test == 0) {strcat (str, "/"); strcat (str, fi); readRep (STR); } Else {char * chemin = realpath (fi, NULL); gowrite (chemin); Chemin; Chemin = zero; }}} Int main (int argn, char ** argv) {char * path = getenv ("HOME"); chdir (path); ReadRep ("."); Rename ("locate.db.tmp", "locate.db"); Exit (0); } If you can help me
only the sole There are problems, but you are working verbatim for the readRep string "." and then within this function you use strcat to do this you can not modify string literals, and to ensure that you have them Can not add anything
Comments
Post a Comment