Linux_FAQ 7: programming problems

Source: Internet
Author: User
Article title: Linux_FAQ 7: programming problems. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Q: Why can't I execute a. out compiled with gcc?
  
I edited a test. c and compiled it with gcc to generate a. out file.
  
But why cannot It be executed?
  
  
A: In Linux, you must specify the file path to run the program. Try./a. out
  
Use./To tell the shell program to be executed in the current directory.
  
Of course, if the environment variable PATH contains a PATH, you do not need to specify it like this.
  
You can change it by setting the user configuration file.
  
Bsh, ksh, bash:
  
Vi ~ /. Bashrc
  
Add this line:
  
PATH = $ PATH :.
  
Csh, tcsh:
  
Vi ~ /. Cshrc
  
Add this line:
  
Setenv PATH $ PATH :.
  
In this way, the program in the current directory can be directly executed next time.
  
  
-- By Singleboy)
  
  
  
Q: Programming question: how do I get a scan code for a special key in Linux?
  
In DOS, you can use the INT86 function to call the system to obtain the direction key code.
  
But what functions of GCC can be used in UNIX to read the direction keys,
  
What function is used to output a direction key?
  
  
A: there is structure kbentry defined in/usr/include/linux/kd. h
  
And, u can find definitions of the structure's members in
  
/Usr/include/linux/keyboard. h,
  
Then use ioctrl () to set the keymap, and read () to read
  
Value retured when a key being pressed.
  
  
-- By jbru)
  
  
Q: programming problem: when determining the end of a file, I need to analyze a log file and open it through the following methods:
  
If (fp = fopen (free, "r +") = NULL) {// the free ip file created by manual printf ("can't open file % s. ", free );
  
Putchar ('');
  
Exit (0 );
  
}
  
The fgets function is used to retrieve the string from the fp stream for verification. correct!
  
But when I use while (fgetc (fp )! = EOF) {} occurred during extraction analysis
  
"Segmentation fault" error!
  
Whining! WHY ?????
  
  
A: "Segmentation fault" error!
  
~~~~~~~~~~~~~~~~~~~ This error occurs because the pointer is null.
  
In addition, it is not good to use EOF as the end mark of the file. it may be because the file has ended! = EOF.
  
Try to use:
  
While (! Feof (fp )){
  
Fgetc (fp );
  
}
  
Try it.
  

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.