programming

How to convince any C developer to dump gcc and use clang

Posted in c, programming on March 6th, 2010 by fseek – 20 Comments

Most C developers I know hate those wrong or incomplete warnings that GCC sometimes give to us. Plus, it seems to always happen when you are in a rush trying to debug something or get the code out.

However today, I saw a screen shot that convinced me to give clang a shot (at least on my test environments). For those who doesn’t know, clang is C/C++ front-end for the LLVM compiler.

Take a look and let me know if you can find one C developer who is not convinced to use clang :)

Clang

Mass search and replace with sed and grep

Posted in programming, sed, tips on March 4th, 2010 by fseek – 2 Comments

Ever had to search and replace a string in multiple files? That’s how to do it with grep and sed

Today at work I was tasked to upgrade the copyright statement on all our PHP, HTML and C files from 2009 to 2010. Plus, it had to be done only on the files that we owned the copyright. That’s how I did:

1- Search for all the files that we own the copyright

$ cd /source
$ grep -r “Copyright OurComapany Inc” *

It will print all files that match our copyright, so we know at least what files we are changing.

2- Search and replace all these files

$ grep -r “Copyright OurComapany Inc” * | cut -d “:” -f 1 | sort | uniq | xargs sed -i ’s/Copyright 2009/Copyright 2010/’

With this command, we will run “sed” to replace the string 2009 to 2010 on all the files that matched our copyright stement. If you wanted to replace all the files, just the following would work:

$ find ./ | xargs sed -i ’s/Copyright 2009/Copyright 2010/’

int fseek(FILE *stream, long offset, int whence);

Posted in c, fseek, programming on February 8th, 2010 by fseek – Be the first to comment

For a site named fseek, the first post had to be about the fseek C function.

The fseek() function sets the file position indicator for the stream
pointed to by stream. The new position, measured in bytes, is obtained
by adding offset bytes to the position specified by whence. If whence is
set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the
start of the file, the current position indicator, or end-of-file, re-
spectively. A successful call to the fseek() function clears the end-of-
file indicator for the stream and undoes any effects of the ungetc(3)
function on the same stream.

Example: How to use fseek to set the file position to the end of a file

FILE *fp;
fp = fopen(“myfile.txt”, “r”);
if(fp)
{
fseek(fp, 0, SEEK_SET);
}

Simple and easy. About this blog? Expect a lot about C, Unix, Linux, programming and hacking in general.