// fix-mp3s.c // Problem: Not exactly sure. It seg faults with a dump. // I know strtok isn't great to use because it modifies and first arguement, but I don't know how else to do this. I've taken many different approaches and still can't get it working #include // ttye0 #include // Displays files with fewer than 2 '-' #include int main(int argc, char *argv[]) { DIR *d; char *ret,*str1; int i; struct dirent *dir; d = opendir(argv[1]); if (argc < 2){ printf("usage: ./fix-mp3s directory (local directory selected)\n"); argv[1] = "."; } if (d){ while ((dir = readdir(d)) != NULL){ strcpy(str1, dir->d_name); i = 0; for ((ret = strtok(str1, "-")); i <= 2; i++){ if ((i == 2) && (ret != NULL)){ printf("Fix: %s\n", str1); } } closedir(d); } } return(0); } // netinfo.c // Can I determine the file size before fread? Or can I run a fread on it and just find the size and rerun fread to get the data the second go? // I want to develop more control over file I/O, this is embarrassing. #include #include #include #include main(){ FILE *stream; char buf[20]; if((stream = fopen("/proc/net/dev","r")) == NULL){ printf("Error: Cannot open /proc/net/dev\n"); } fread(buf, 20, 40, stream); // Why can't it see EOF? printf("%s\n", buf); fclose(stream); return 0; } // pid-mon.c // Big problem, easily fixable, unknown solution. // It's supposed to return pid status, but waitpid only works on child processes...what function do I catch main (what's the term?) process status with? #include #include #include #include #include #include #include main(int argc, char *argv[]){ struct sigaction sa; int sigstat,mypid; if (argc < 2){ printf("usage: ./pid-mon pid\n"); exit(1); } mypid = strtoumax(argv[1],NULL,2); if ((waitpid(mypid, &sigstat, WNOHANG)) == -1){ perror("waitpid"); exit(1); } printf("Status: %d\n", sigstat); } //MAIN