textwidth() function in C Last Updated : 23 Jan, 2018 Comments Improve Suggest changes Like Article Like Report The header file graphics.h contains textwidth () function which returns the width of input string in pixels. Syntax : int textwidth(char *string); Example : Input : string = "Hello Geek ! Have a good day." Output : Below is the implementation of textwidth() function. C // C Implementation for textwidth() #include <graphics.h> #include <stdio.h> //driver code int main() { // gm is Graphics mode which is // a computer display mode that // generates image using pixels. // DETECT is a macro defined in // "graphics.h" header file int gd = DETECT, gm, color, width; char arr[100]; // initgraph initializes the // graphics system by loading a // graphics driver from disk initgraph(&gd, &gm, ""); // textwidth function width = textwidth("Hello Geek ! Have a good day."); //sprintf stands for “String print”. //Instead of printing on console, //it store output on char buffer //which are specified in sprintf sprintf(arr, "Textwidth is = %d", width); //outtext function displays text //at current position. outtext(arr); getch(); // closegraph function closes the // graphics mode and deallocates // all memory allocated by // graphics system . closegraph(); return 0; } Output : Comment S Sahil_Bansall Follow 0 Improve S Sahil_Bansall Follow 0 Improve Article Tags : Misc C Language computer-graphics c-graphics Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like