-
-
Save marceloboeira/fd7cd193a6d4ff5d67b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string.h> | |
#define FILE_NAME "data.txt" | |
#define MAX_CHARS 100 | |
FILE *getFile(int write) { | |
return (write == 1) ? fopen(FILE_NAME,"a+") : fopen(FILE_NAME,"r+"); | |
} | |
void writeFile(char *b) { | |
FILE *f = getFile(1); | |
fputs(b,f); | |
fclose(f); | |
} | |
int main(){ | |
char *buffer; | |
buffer = malloc(MAX_CHARS * sizeof (char) ); | |
printf("Write the file contents:"); | |
scanf("\n%s",buffer); | |
writeFile(buffer); | |
printf("\nThanks!\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#define FILE_NAME "data.txt" | |
#define MAX_CHARS 10000 | |
FILE *getFile(int write) { | |
return (write == 1) ? fopen(FILE_NAME,"w") : fopen(FILE_NAME,"r"); | |
} | |
char *loadFile () { | |
FILE *f = getFile(0); | |
char *final,_lineBuffer[500]; | |
int j = 0; | |
final = malloc(MAX_CHARS * sizeof(char)); | |
while (fgets(_lineBuffer, 500, f)!= NULL){ | |
strcat (final, _lineBuffer); | |
} | |
fclose(f); | |
return final; | |
} | |
int main(){ | |
char *bf,*sc, *fc = loadFile(); | |
printf("The File Contents: \n%s\n",fc); | |
bf = malloc(100 * sizeof (char) ); | |
printf("\nType something:"); | |
scanf("%s",bf); | |
sc = strstr(fc, bf); | |
if (sc) { | |
printf("\n\"%s\" was found in the file!\n",bf); | |
} | |
else { | |
printf("\n\"%s\" was NOT found in the file!\n",bf); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marCelo | |
teste | |
palavra | |
engineer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment