Continue to study C and file today

Source: Internet
Author: User

When fopen fails,
Getch ();
Exit (1 );
The compilation fails, prompting that the two do not exist...
Man.
# Include <curses. h> This includes getch (), wgetch (), and so on...
# Include <stdlib. h> This includes the exit (INT value) function...

After that, another problem occurs:
[Ktktkt @ Jintao cprogram] $ GCC 1.C-O 1-wall
1. C: In function 'main ':
1. C: 9: Warning: Assignment makes pointer from integer without a cast
/Tmp/cc0cwbi1. O (. Text + 0x4c): In function 'main ':
: Undefined reference to 'stdscr'
/Tmp/cc0cwbi1. O (. Text + 0x51): In function 'main ':
: Undefined reference to 'wgetch'
Collect2: LD returned 1 exit status

I cannot understand this... stdscr does not have man-related introduction. And I do not know what these compilation errors mean...
It seems that stdscr is used by getch...
This compilation fails. In the cause search, Echo $? In bash? Also return 1, it seems there is an error... it would be nice if you have a friend who gives directions :)

Code:
# Include <stdio. h>
# Include <curses. h>
# Include <stdlib. h>
Int main ()
{

File * FP;

If (FP = fopen ("/usr/include/stdio. H", "R") = NULL)
{
Printf ("/nerror on open stdio. h/N ");
Getch ();
Exit (1 );
}

Fclose (FP );
Return 0;
}

It turned out to be like this:
# GCC 1.C-O 1-wall-lcurses
You need to use the curses library. Although the header file contains only the function name, the header file does not implement the function (getch (). Therefore, you must connect to the library...

After reading this, whereis was used to find the library.
[Ktktkt @ Jintao file] $ whereis libcurses
Libcurses:/usr/lib/libcurses. So/usr/lib/libcurses.
There seems to be another static Link Library ~

Well, the whole code for Directly Reading a file is stupid. One character and one character can be read.
# Include <stdio. h>
# Include <stdlib. h>
# Include <curses. h>

Int main ()
{
Char C;
File * FP;

If (FP = fopen ("file", "R") = NULL)
{
Printf ("cannot open the file, please press any key to exit/N");
Getch ();
Exit (1 );
}

C = fgetc (FP );
While (C! = EOF)
{
Putchar (C );
C = fgetc (FP );
}

Fclose (FP );
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.