You are here

Textwidth function in c

Textwidth function returns the width of a string in pixels.

Declaration: int textwidth(char *string);

C programming source code for textwidth

  1. #include <stdio.h>
  2. #include <graphics.h>
  3. #include <conio.h>
  4.  
  5. int main()
  6. {
  7.    int gd = DETECT, gm, width;
  8.    char array[100];
  9.  
  10.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  11.  
  12.    width = textwidth("C programming");
  13.  
  14.    sprintf(array,"Textwidth = %d",width);
  15.    outtext(array);
  16.  
  17.    getch();
  18.    closegraph();
  19.    return 0;
  20. }