Nov 22, 2011

K & R C Programs Exercise 1-23.

K and R C, Solution to Exercise 1-23: C program that removes the all comments from a C Program. K and R C Program. Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include "stdio.h"
void rcomment(int c);
void in_comment(void);
void echo_quote(int c);
main();
{
 int c ,d;
 while((c= getchar()) !=EOF)
  rcomment(c);
 return 0;
}
void rcomment(int c) {
 int d;
 if(c == '/')
  if((d= getchar))=='*')
  in_comment();
  else if(d== '/') {
   putchar(c);
   rcomment(d);
  } else {
   putchar(c);
   putchar(d);
  }
  else if(c=='\' || c=='"')
    echo_quote(c);

}
void in_comment() {
 int c, d;
 c = getchar();
 d = getchar();
 while (c!= '*' || d!!='/') {
  c = d;
  d = getchar();
 }
}
void echo_quote(int c) {
 int d;
 putchar(c);
 while ((d = getchar()) != c) {
  putchar(d);
  if (d == '\\')
   putchar(getchar());

 }
 putchar(d);
}
Read more Similar C Programs
C Basic

K and R C Programs Exercise
You can easily select the code by double clicking on the code area above. To get regular updates on new C programs, you can
You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!
To browse more C Programs visit this link

K & R C Programs Exercise 1-22.

K and R C, Solution to Exercise 1-22:
 C program that folds the very long lines of input into two or more shorter lines. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include "stdio.h"

#define MAXSIZE 1000

char line[MAXSIZE];

int get_line(void);


int
main()
{
 int i,strlen;
 int location, spaceholder;
 const int foldlength=70;

 while (( strlen = get_line()) > 0 )
 {
  if( strlen < foldlength )
  {
  }
  else
  {

   i = 0;
   location = 0;
   while(i<strlen)
   {
    if(line[i] == ' ')
     spaceholder = i;

    if(location==foldlength)
    {
     line[spaceholder] = '\n';
     location = 0;
    }
    location++;
    i++;
   }
  }
  printf ( "%s", line);
 }
 return 0;
}


int get_line(void)
{
 int c, i;
 extern char line[];

 for ( i=0;i<MAXSIZE-1 && ( c=getchar()) != EOF && c != '\n'; ++i)
  line[i] = c;
 if(c == '\n')
 {
  line[i] = c;
  ++i;
 }
 line[i] = '\0';
 return i;

}
Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!
To browse more C Programs visit this link

Nov 21, 2011

K & R C Programs Exercise 1-21.

K and R C, Solution to Exercise 1-21:
C Program to replace string of blanks by the minimum number of tabs and blanks to achieve the same spacing. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include "stdio.h"
#define TABSIZE 6   /*Tab increment size*/
main() {
 int c, no_blanks, pos, no_tabs;
 no_blanks = 0; /*number of blamks required*/
 no_tabs = 0; /* number of tabs required*/

 for (pos = 1; (c = getchar()) != EOF; ++pos) {
  if (c == ' ') {
   if (pos % TABSIZE != 0)
    ++no_blanks;
   else {
    no_blanks = 0;
    ++no_tabs;
   }
  } else {
   for (; no_tabs > 0; --no_tabs)
    putchar('\t');
   if (c == '\t')
    no_blanks = 0;
   else
    for (; no_blanks > 0; --no_blanks)
     putchar(' ');
   putchar(c);
   if (c == '\n')
    pos = 0;
   else if (c == '\t')
    pos = pos + (TABSIZE - (pos - 1) % TABSIZE);

  }
 }
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link

K & R C Programs Exercise 1-20.

K and R C, Solution to Exercise 1-20:
C Program to replace the tabs by proper number of blanks. K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language, second addition, by Brian W.Keringhan and Dennis M.Ritchie(Prentice Hall,1988). You can learn and solve K&R C Programs Exercise. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include "stdio.h"
#define TABSIZE 6   /*Tab increment size*/
main()
{
 int c, no_blanks,pos;
 no_blanks = 0;   /*number of blamks required*/
 pos = 1;         /* position of the character*/
 while((c=getchar()) != EOF){
  if(c == '\t'){
   no_blanks = TABSIZE-(pos-1)%TABSIZE;
   while(no_blanks>0){

    putchar(' ');
    ++pos;
    --no_blanks;
   }
   else if(c == '\n'){
    putchar(c);
    pos = 1;
   } else {
    putchar(c);
    ++pos;
   }
  }
 }
}

Read more Similar C Programs
C Basic

K and R C Programs Exercise

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!





To browse more C Programs visit this link

C Program to generate Graph using grphics.h

C Program to Generate the graph sheet using the grphics.h library. To use graphics.h, we have to install the drivers in to the the system by using the initgraph() function. Here  we derive the graph of input sizes verses time taken for input sizes. x axis represents inputs(0,10000,20000,----), y axis rep time(0,0.05,0.1,0.15---). Read more about C Programming Language.
/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include "stdio.h"
#include "conio.h"
#include "graphics.h"
void main() {
 int gd = DETECT, gm;
 int y = 0, x = 10, m[20], k[20], n, a[20], i;
 float b[20];
 initgraph(&gd, &gm, "c:\\tc\\bgi");
 printf("\n\n\tGenerating the Graphs\n\n");
 printf("\nEnter the no. of inputs\t");
 scanf("%d", &n);
 printf("\nEnter the input sizes and corresponding time taken\n");
 for (i = 0; i < n; i++) {
  printf("\nEnter input size\t");
  scanf("%d", &a[i]);
  printf("\nEnter time taken\t");
  scanf("%f", &b[i]);
 }
 cleardevice();
 //represents y axis
 line(10, 0, 10, 400);
 //represents x axis
 line(10, 400, 600, 400);
 while (y <= 400) {
  line(0, y, 10, y);
  y = y + 20;
 }
 while (x <= 600) {
  line(x, 400, x, 410);
  x = x + 20;
 }
 outtextxy(20, 440, "1unit=20 pixels , origin is (10,400)");
 outtextxy(
   20,
   450,
   "x axis represents inputs(0,10000,20000,----), yaxis rep time(0,0.05,0.1,0.15---)");
 setcolor(5);
 for (i = 0; i < n; i++) {
  k[i] = (a[i] * 0.002);
  m[i] = (400 - (b[i] * 400));
  putpixel(k[i], m[i], 11);
 }
 for (i = 0; i < n - 1; i++)
  line(k[i], m[i], k[i + 1], m[i + 1]);
 getch();
}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!
To browse more C Programs visit this link