मैं अपने सी प्रोग्राम के भीतर से टर्मिनल चौड़ाई प्राप्त करने का एक तरीका ढूंढ रहा हूं। की तर्ज पर कुछ क्या मैं के साथ आते रहते है:सी में टर्मिनल चौड़ाई प्राप्त करना?
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct ttysize ts;
ioctl(0, TIOCGSIZE, &ts);
printf ("lines %d\n", ts.ts_lines);
printf ("columns %d\n", ts.ts_cols);
}
लेकिन हर मैं कोशिश मुझे मिलता है कि
[email protected]:~$ gcc test.c -o test
test.c: In function ‘main’:
test.c:6: error: storage size of ‘ts’ isn’t known
test.c:7: error: ‘TIOCGSIZE’ undeclared (first use in this function)
test.c:7: error: (Each undeclared identifier is reported only once
test.c:7: error: for each function it appears in.)
इस यह करने के लिए सबसे अच्छा तरीका है, या वहाँ एक बेहतर तरीका है? यदि नहीं, तो मैं इसे काम करने के लिए कैसे प्राप्त कर सकता हूं?
संपादित करें: निर्धारित कोड
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct winsize w;
ioctl(0, TIOCGWINSZ, &w);
printf ("lines %d\n", w.ws_row);
printf ("columns %d\n", w.ws_col);
return 0;
}
हाँ लेकिन शब्द चौड़ाई एक पर्यावरणीय चर नहीं है, यह शब्द के लिए स्थिर है। – austin
यह आपको _current_ टर्मिनल आकार प्रदान नहीं करता है, अगर कोई प्रोग्राम के निष्पादन के दौरान टर्मिनल का आकार बदलता है। –
हाँ, जोड़ने की गई कि :) –