Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
FILE Access 2
//gcc 5.4.0 #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <string.h> unsigned char val; FILE *file_ptr=NULL, *fp_path=NULL; char fpath[100]="C:\\Users\\stodorov\\Downloads\\Notes\\Address book FS team.txt"; char filenames[500][30]; char path_bool[]="0,0,0"; //-------------------- Reading the filenames --------------- void getfilenames() { DIR *dir; struct dirent *ent; unsigned int i; if ((dir = opendir ("C:\\Users\\stodorov\\Downloads\\Notes\\")) != NULL) { i=0; memset(filenames,'\0',sizeof(filenames)); while((ent = readdir (dir)) != NULL) { puts (ent->d_name); strcpy(filenames[i++],ent->d_name); } (void) closedir (dir); //strcpy(filenames[i],not_founded); } else perror ("Couldn't open the directory"); } //------------------------ Path Set ------------------------ void path_set() { printf("The default path is : %s\n\n\r",fpath); /*printf("Y/N?"); //while(path_bool[0]==0) scanf("%s",&path_bool); if(path_bool[0]=='N') { printf("Enter path:"); scanf("%s",fpath); } printf("The set path is : %s\n\n\r",fpath); */ } //--------------------------------------------------------- void read_file() { char temp; file_ptr=fopen(fpath,"r+"); if(file_ptr==NULL) printf("Error opening file %s\n", fpath); else { temp = fgetc(file_ptr); fclose(file_ptr); printf("char=%c",temp); } } //-------------------------- MAIN ------------------------- int main(void) { path_set(); //getfilenames(); read_file(); return 0; } /*========================================================== DIR *dir; struct dirent *ent; if ((dir = opendir ("c:\\src\\")) != NULL) { while ((ent = readdir (dir)) != NULL) { printf ("%s\n", ent->d_name); } closedir (dir); } else { // could not open directory perror (""); return EXIT_FAILURE; }*/
run
|
edit
|
history
|
help
0
Mutex Safe
1.c
Project 3 Part 1 v1.3
PPCG partial solution to https://codegolf.stackexchange.com/q/120870/61563
Dynamic array
150109_RecursividadFactorial
X=2
Lab 9 v0.95
In Class 1.23.17 Bit operations
20171127_ARRAY_PRIMOS