Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <memory.h>
- int main(int argc, char *argv[]) {
- char text[100];
- printf("Podaj tekst: ");
- gets(text);
- int length = 0;
- while (text[length] != '\0') length++;
- printf("Długość: %d\n", length);
- printf("Długość funkcją strlen: %zu\n\n", strlen(text));
- FILE *file = fopen("/tmp/tekstowy_plik", "w+");
- if (file == NULL) {
- printf("Sth went wrong\n");
- return 0;
- }
- for (int i = 0; text[i] != '\0'; i++)
- fputc(text[i], file);
- printf("Zapisano do pliku\n");
- rewind(file);
- char content[100];
- for (int i = 0; ; i++) {
- int c = fgetc(file);
- if (feof(file)) break;
- content[i] = (char) c;
- }
- printf("Odczytano następującą treść:\n\n");
- for (int i = 0; content[i] != '\0'; i++) {
- printf("%c", content[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment