Posts

SNAK GAME IN C

Graphics Programming in c (RAIN)

4. Write a program to read a text file “brijesh.txt “ count and display the number of alphanets present in it.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include<conio.h> int main(void) { char str[80]; int l=0; clrscr(); FILE *fp; if((fp = fopen("brijesh.txt", "w"))==NULL) { printf("Cannot open file.\n"); exit(1); } do { printf("Enter a string :\n"); gets(str); l=strlen(str); printf("charecter lenth are\t%d\n",l); strcat(str, "\n"); /* add a newline */ fputs(str, fp); } while(*str!='\n'); return 0; }

6. Write a program to create a text file which contain some text.

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char str[80]; FILE *fp; if((fp = fopen("brijesh.txt", "w"))==NULL)  { printf("Cannot open file.\n"); exit(1); } do { printf("Enter a string (CR to quit):\n"); gets(str); strcat(str, "\n"); /* add a newline */ fputs(str, fp); } while(*str!='\n'); return 0; }

c program for swapping with the help of pointer

#include<stdio.h> #include<conio.h> void swap(int*,int*); void main() {   int a,b;   clrscr();   printf("enter two value\n");   scanf(" %d%d",&a,&b);   swap(&a,&b);   getch();   }   void swap(int *a,int *b)   {    int *c;    *c=*a;    *a=*b;    *b=*c;    printf("value Are=%5d\t%d",*a,*b);    }

ALL DOS COMMAND

C program for conver kilometer into inch ,feet,centimeter and meter

#include<stdio.h> #include<conio.h> void main() { float km,m,cm,ft,inch; clrscr(); printf("enter the distance in kilometres "); scanf("%f",&km); m=km*1000; cm=m*100; C inch=cm/2.54; ft=inch/12; printf(" distance in meters is %f",m); printf(" distance in centimetres is %f",cm); printf(" distance in feet is %f",ft); printf(" distance in inches is %f",inch); getch(); }