Sunday 14 October 2012

what does printf returns


"printf returns the number of charecters printed" 

#include<stdio.h>
#include<conio.h>


int main()
{
    int k=0;
    k=printf("kdhsafuh");
    printf("\nk=%d",k);
    getch();
    return 0;
}

output:k=8

Saturday 13 October 2012

Friday 12 October 2012

c programm to count the number of lines

#include <stdio.h>
/* count lines in input */

main()
{
int c, nl;
nl = 0;
while ((c = getchar()) != EOF)
if (c == '\n')
++nl;
printf("%d\n", nl);
}

Thursday 11 October 2012

The following program erases the file specified on the command line.


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
char str[80];
if(argc!=2) {
printf(''usage: xerase <filename>\n");
exit(1);
}
printf("Erase %s? (Y/N): ", argv[1]);
gets(str);
if(toupper(*str)=='Y')
if(remove(argv[1])) {
printf("Cannot erase file.\n");
exit(1);
}
return 0;
}

Wednesday 10 October 2012

declaration vs definition

A declaration provides basic attributes of a symbol: its type and its name. A definition provides all of the details of that symbol--if it's a function, what it does; if it's a class, what fields and methods it has; if it's a variable, where that variable is stored. Often, the compiler only needs to have a declaration for something in order to compile a file into an object file, expecting that the linker can find the definition from another file. If no source file ever defines a symbol, but it is declared, you will get errors at link time complaining about undefined symbols.

 

Tuesday 9 October 2012

identifier in c and c++


In C, identifiers may be of any length. However, not all characters will necessarily be significant. C defines two kinds of identifiers: external and internal. An external identifier will be involved in an external link process. These identifiers, called external names, include function names and global variable names that are shared between source files. If the identifier is not used in an external link process, then it is internal. This type of identifier is called an internal name and includes the names of local variables, for example. In C89, at least the first 6 characters of an external identifier and at least the first 31 characters of an internal identifier will be significant. C99 has increased these values. In C99, an external identifier has at least 31 significant characters, and an internal identifier has at least 63 significant characters. As a point of interest, in C++, at least the first 1,024 characters of an identifier are significant. These differences may be important if you are converting a program from C89 to C99, or from C to C++.

keep in mind while compiling the c programme in an c++ compiler


In general, you can use a C++ compiler to compile a C program. In fact, today most compilers
handle both C and C++ programs. Thus, most programmers will use a C++ compiler to compile
their C code! However, since C++ was built upon the 1989 C standard, you must restrict your C
code to the features defined by that standard .(yor are not permited to use the features of c99)



There is one thing that you must be careful about when using a C++ compiler to compile a C
program: the file extension. By convention, C programs use the .C extension. C++ programs
use .CPP. Don't accidentally give your C program a .CPP extension. Differences between the two
languages might prevent a valid C program from being compiled
as if it were a C++ program. By
specifying the .C extension, you are telling the C++ compiler to perform a ''C compile.

Monday 8 October 2012

high level,low level and middil level languages

 

/*................know the language levels..............*/
High level

Ada
Modula-2
Pascal
COBOL
FORTRAN
BASIC
Middle level
Java
C++
C
FORTH
Macro-assembler
Low level Assembler

How to setup graphics.h library in devcpp compiler

having dout how to use  " graphics.h " library in "devc++"

solution:

1.open devc++ compiler
2.select new project and select empty project
3.download grapgics library functions graphics.h and libbgia from the link provided
4.http://www.cs.colorado.edu/~main/bgi/dev-c++/
5.after downloading copy graphics.h library to c:/devcpp/include  folder
6.libbia file to "c:/devcpp/lib folder
7.write a sample graphic program or download a sample programe which i compiled and uploaded to the following mediafire link
8.http://www.mediafire.com/?d07ihy86g29orq8
9.go to project on toolbar->project options->parameters->in linker section paste the following :

-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

10.now compile and your programme should execute

11.note:if you download the programe you probably get error because you will not have the images that i importred so better to write your sample and simple programe and verify

Allegro library

allegro is the  library that allowes to develop the games  through c/c++

find allegro library @:allegro.cc

sample programme:pong game through allegro

Sunday 7 October 2012

ascii value of EOF

in c language ascii value of EOF(end of file)=-1(mostly)
because it is compiler dependent

Saturday 6 October 2012

"subscribe to my blog and experience the power of c language"

the way to getout the rust of getchar() function

#include<stdio.h>

int main()
{

char c;

c=getchar();
printf("%d",c);
c=getchar();
printf("%d",c);
}

output:     suppose if u enter charecter 'a' as input: followed by b
    the output will be 97

10(ascii value of enter)

reason:"getchar automatically inserats newline charecter after taking input hence  by second getchar c takes the innput charecter \n from input buffer"

____to avoid this add "fflush(stdin)" command after first printf statement which washes away all the input charecters presenent in input buffer