WiFi issues on Ubuntu 12.04

Hey ,

Recently installed ubuntu 12.04 on a fresh and clean system. While it works like a charm, a very irritating issue was that the inbuilt wireless card was not working. The ethernet connection using wire worked fine. Googled a lot and wasnt able to figure things out. Finally, backports saved my day. Here is the procedure I followed incase someone finds it useful.

 

Installing backports:

sudo apt-get install  linux-backports-modules-cw-3.8-precise-generic 

Some generic headers and libraries:

sudo apt-get install linux-headers-generic build-essential

Download this file and extract it at a location of your choice.
Navigate to the extracted directory using terminal and try:

make defconfig-ath9k
make
sudo make install

Reboot the system and ideally wireless should work!

Hope it helps.

Standard String Library functions in string.h in C

FUNCTION USE
strlen Finds the length of the string.
strlwr Converts string to lower case.
strupr Converts string to upper case.
strcat Appends one string at end of another.
strncat Appends first n characters of a string at end of another.
strcpy Copies a string to another.
strncpy Copies first n characters of a string into another.
strcmp Compares two strings
strncmp Compares first n characters of two strings.
strcmpi Compares two strings without regards to case.
stricmp Compares two strings without regards to case.
strnicmp Compares first n characters of a string without regards to case.
strdup Duplicates a string.
strchr Finds first occurrence of a given character in a string.
strrchr Finds last occurrence of a given character in a string.
strstr Finds first occurrence of a given string in a string.
strset Sets all characters of a string to given character.

 

strnset Sets first n characters of a string to given character.
strrev Reverses the string.
   

Conditional Compilation in C

C provides a very useful and interesting feature called “conditional Compilation

the general structure for doing it:

#ifdef macroname

statement 1;
statement 2;
statement 3;
statement 4;
#endif

here if macroname has been #defined then the 4 statements will be compiled otherwise not.

There are 3 scenarios where I see application of this feature:

-> To “comment out” obselete lines of code. It may happen that a program undergoes a change for some reasons.
Here we may not want to delete the old code but add new code.
In this scenario, we can include the old and new code in ifdef block and control the compilation using a single #define statement.

eg:

void main()
{

#ifdef OLD
statement 1;
statement 2;
#else
statement 3;
statement 4;

#endif

}

here , if we define thee macro “OLD” then old code is compiled otherwise, the new code is compiled.

->The other (more sophisticated) use of this feature can be to make the programs more portable.
Thus, we can make use of this feature and make a program work on two completely different computers.

eg:

void main()
{
#ifdef INTEL
code for intel PC
#else
code for motorola PC
#endif
code common for both.

}

This code is pretty self explanatory.
If you want your code to run on INTEL we just need to define a macro.

->A third possible scenario is defining of custom functions.
Lets say we define a function called “my_sample_function()” in a file “file1.h”
Also, “file1.h” is included in “file2.h

If we include both the files, compiler will throw an error saying “multiple declaration of my_sample_function()

To overcome this problem, we can use the following way:

/* file1.h */

#ifndef _file
#define _file
my_sample_function()
{
/*some code */
}
#endif

Here when file1.h gets included first time, compiler knows that macro _file is not defined. Thus it gets defined and the rest of code is compiled.
Next time, since the macro stands defines, the function does not get compiled and thus there is no error.

NOTE: #ifndef is exactly opposite of #ifdef

 

Conditional compilation can also be achieved using #if ,#else #endif statements.

#if is used to evaluate whether a expression evaluated to nonzero value or not.

it is used in the same way as above:

eg:

 

void main(){

if TEST<=5

statment 1;

#else

statement 2;

#endif

}

Ways to include a file in C

There are two ways of including a file in C using #include statement:

#include “filename”

This command would look for the file in the current directory as well as the specified list of directories as mentioned in the include search path that might have been setup.

 

#include <filename>

This command would look for the file on the specified list of directories only.

 

 

 

Datatypes in C

Datatypes sumary in C:

Data Type Range Bytes Format
 signed char -128 to +127  1 %c
 unsigned char  0 to 255  1 %c
 short signed int -32768 to +32767 2 %d
 short unsigned int 0 to 65535 2 %u
signed int  -32768 to +32767  2 %d
 unsigned int 0 to 65535  2  %u
 long signed int  -2147483648 to +2147483647 4 %ld
 long unsigned int 0 to 4294967295 4 %lu
float  -3.4e38 to +3.4e38  4  %f
 double  -1.7e308 to +1.7e308  8  %lf
 long double  -1.7e4932 to +1.7e4932  10  %Lf
-32768 to +32767 2 %d
The sizes and ranges of int,short and long are compiler dependent. The above data is for 16 bit compiler.

Adding Functions to Library in C

This might be known to many but  I recently tried it and got it working.

Suppose you make a function in C(for example here we take a simple function which calculates the square of a number).

Its a fairly simple one and I want to add in in a library thus making its reuse possible.

(Please note I am taking a very simple scenario because the actual program is not the point of focus here, but the procedure is)

The function:

int square(int n)

{

return n*n;

}

Compile the file:

Compile the file in which you have written this function. Lets call it “sqr.c”. A new file called “sqr.obj” is created contained compiled code.

Add the function to Library:

Add the function to the library “maths.lib” using the following command.

C:\>tlib maths.lib + c:\sqr.obj

Please note the paths. Your paths may be different than mine!

here, maths.lib is the library and + is a switch which indicates that we want to add a new function to the library and the object file is at the given path.

Header file:

Add the prototype of square() function in a header file (lets say “square.h”) This file should be included in the program where we want to use the function. we can use it as:

#include “c:\square.h”

Thats all !

Use the function and enjoy !!

Hope it helps.