[Tips] source code running error-Linux general technology-Linux programming and kernel information. For details, refer to the following section. Source code:
# Include
# Include
# Include
# Include
# Include
# Define PERM 0755
# Define Buff 512
/* String open ()
{
Static char filename [] = "t1.txt ";
Int handle;
Handle = open (filename, O_RDONLY );
If (handle =-1)
Printf ("% s does not exist \ n", filename );
Else
Printf ("open success \ n ");
}*/
String close ()
{
Static char filename [] = "t1.txt ";
Int handle;
Int ret;
Handle = open (filename, O_RDONLY );
If (handle =-1)
Printf ("% s does not exist \ n", filename );
Else
Printf ("open success \ n ");
Ret = close (handle );
If (ret = 0)
Printf ("close file success \ n ");
Else
Printf ("close file error \ n ");
}
String creat ()
{
Static char filename [] = "t1.txt ";
Int handle;
Handle = creat (filename, PERM );
If (handle =-1)
Printf ("% s create fail \ n", filename );
Else
Printf ("open success \ n ");
}
String write (int argc, char * argv)
{
Char buffer [Buff];
Int source, dest;
Int count;
If (argc! = 3)
{Printf ("sorry input error \ n ");
Exit (1 );}
Source = open (argv [1], O_RDONLY );
If (source =-1)
{Printf ("sorry input error \ n ");
Exit (1 );}
Dest = creat (argv [2], PERM );
If (dest =-1)
{Printf ("% s creat error \ n", argv [2]);
Exit (1 );}
While (count = read (source, buffer, Buff)> 0)
Write (dest, buffer, count );
}
String read ()
{
Static char filename [] = "t1.txt ";
Char buffer [Buff];
Int handle, I;
Int total = 0;
Handle = open (filename, O_RDONLY );
If (handle =-1)
{Printf ("open file fail \ n ");
Exit (1 );}
Else
While (I = read (handle, buffer, Buff)> 0)
Total + = I;
Printf ("The total character in % s is % d \ n", filename, total );
}
String chmod ()
{
Static char file [] = "t1.txt ";
If (chmod (file, 0700) =-1)
{
Printf (stderr, "chmod for file is error \ n", file );
Exit (1 );
}
Printf ("% s mod for file has been changed \ n", file );
}
Main ()
{
Printf ("0 exit \ n ");
Printf ("1 creat a new file \ n ");
Printf ("2 write \ n ");
Printf ("3 read a file \ n ");
Printf ("4 change the potence \ n ");
Printf ("5 check the and exit \ n ");
Printf ("please input a number from 0 to 5: \ n ");
Int x;
Scanf ("% d \ n", & x );
Switch (x)
{
Case '0': close ();
Case '1': creat ();
Case '2': write (int argc, char * argv );
Case '3': read ();
Case '4': chmod ();
}
}
Running result:
6. c: 20: Error: expected '=', ';', 'asm 'or' _ attribute _ 'before' close'
6. c: 38: Error: expected '=', ';', 'asm 'or' _ attribute _ 'before' creat'
6. c: 49: Error: expected '=', ';', 'asm 'or' _ attribute _ 'before' write'
6. c: 69: Error: expected '=', ';', 'asm 'or' _ attribute _ 'before' read'
6. c: 85: Error: expected '=', ';', 'asm 'or' _ attribute _ 'before 'chmod'
6. c: In the 'main' function:
6. c: 110: Error: Too few arguments are provided to the function 'close '.
6. c: 111: Error: Too few arguments are provided to the 'creat' function.
6. c: 112: Error: expected expression before 'int'
6. c: 112: Error: Too few arguments are provided to the 'write' function.
6. c: 113: Error: Too few arguments are provided to the 'read' function.
6. c: 114: Error: Too few arguments are provided to the 'chmod' function.
This cainiao really does not understand what went wrong with the source code. I hope the prawns can help solve the problem ~~~
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