Skip to content

Instantly share code, notes, and snippets.

@lygstate
Created June 7, 2012 08:02
Show Gist options
  • Save lygstate/2887315 to your computer and use it in GitHub Desktop.
Save lygstate/2887315 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#include<unistd.h>
#define SIZE_4K 1024*4
int getFileSize(char * strFileName)
{
int size;
FILE *fp = fopen(strFileName, "r");
fseek(fp, 0L, SEEK_END);
size = ftell(fp);
fclose(fp);
return size;
}
void revere_string(char*str, int len)
{
int i;
char temp_char;
for (i = 0; i < len / 2; i++)
{
temp_char = str[i];
str[i] = str[len - i - 1];
str[len - i - 1] = temp_char;
}
}
int main()
{
int len = getFileSize("4kb.txt");
char buf[len];
int fd;
fd = open("4kb.txt", O_RDWR);
if (fd == -1)
{
return -1;
}
else
{
read(fd, buf, 1);
}
close(fd);
if ((fd = open("4kb.txt", O_RDWR)) == -1)
{
return -1;
}
else
{
revere_string(buf, len);
write(fd, buf, 1);
}
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment