728x90
반응형
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
/* Read a file and remove the spaces between words */
int main(void)
{
FILE* filePtr;
char fileBuff[255];
int fileChar;
//open file
filePtr = fopen("C:\\Users\\hrmk\\OneDrive\\바탕 화면\\fox.map", "rt");
if (filePtr)
{
// Read and print file content
fgets(fileBuff, 255, filePtr);
printf("The contet of the file is : \n%s", fileBuff);
// Move file cursor to the start of the file
fseek(filePtr, 0, SEEK_SET);
printf("\n\nAfter removing the spaces the content is : \n");
do
{
// Read a character from the file
fileChar = fgetc(filePtr);
// Display if character is a graphic character
if (isgraph(fileChar))
{
putchar(fileChar);
}
}
while (fileChar != EOF);
// Close the file
fclose(filePtr);
}
else
{
printf("\nFile cannot be opened");
}
return 0;
}
728x90
반응형
'Language > C & C++' 카테고리의 다른 글
[C] How to Handle String (0) | 2022.10.25 |
---|---|
[C] Convert matrix from text file (0) | 2022.10.23 |
[C] Function to remove spaces from a string (0) | 2022.10.22 |
[C]File Input & Ouptut (0) | 2022.10.22 |
Function practice (0) | 2022.10.19 |