Posts

Showing posts from February, 2014

File Programming

#include<stdio.h>     int main()     {         FILE *ptr_file;         int x;         ptr_file =fopen("output.txt", "w");         if (!ptr_file)             return 1;         for (x=1; x<=10; x++)             fprintf(ptr_file,"%d\n", x);         fclose(ptr_file);         return  0;     }

String Programming

Image
C Programming String In C programming, array of character are called strings. A string is terminated by null character  /0 . For example: "c string tutorial" Here, "c string tutorial" is a string. When, compiler encounters strings, it appends null character at the end of string. Declaration of strings Strings are declared in C in similar manner as arrays. Only difference is that, strings are of  char  type. char s[5]; Strings can also be declared using pointer. char *p Initialization of strings In C, string can be initialized in different number of ways. char c[]="abcd"; OR, char c[5]="abcd"; OR, char c[]={'a','b','c','d','\0'}; OR; char c[5]={'a','b','c','d','\0'}; String can also be initialized using pointers char *c="abcd"; Reading Strings from user. Reading words from user. char c[20]; scanf("