To truncate a text file using system call
Hello people,
I am studying a small piece of code to truncate a text file using system call. This is the code. Code:
#include<stdio.h> Code:
$ gcc trun.c -o trun Code:
bash: ./truncate: No such file or directory Regards... |
pirate.txt is in the same directory as trun ?
|
@Cedrik
I have edited a pirate.txt file as an example. I do not know its location. How to find out whether they are the same directory? |
Hu ? just type "ls" and enter to list files in the current directory
|
@Cedrik
I moved pirate.txt. Pirate.txt is not in the same directory as trun. |
But it has to be in the same dir as trun
"./pirate.txt" => relative path that means file pirate.txt is in the current directory |
@Cedrik
I moved pirate.txt again, Now when i run ls command, pirate.txt as well as trun.c are listed in the current directory. I recompiled and still not able to. Any other alternative? Thanks |
Sorry :o
I did not read the error carefully Code:
bash: ./truncate: No such file or directory Try: Code:
./trun |
@Cedrik
Oh no I am sorry too. I wrote two identical programs just to clarify. Truncate.c and Trun.c and misplaced the error code. I have Executed ./trun too. I am getting the exact same error. :o |
I'm confused. Did the compilation succeed and generated a file named "trun" in your current directory?
|
@ydoom
Compilation is successful, i.e I am getting no errors or warnings after I run $ gcc trun.c -o -trun. After i run ./trun bash says No such file or directory!!?? :Pengy: |
Just a side note, I hope: if you run
Code:
gcc trun.c -o -trun But let's assume that the file "trun" exists :) Try running "strace trun", this return (for me), when there's no file "pirate.txt": Code:
execve("./trun", ["trun"], [/* 60 vars */]) = 0 Code:
truncate("./pirate.txt", 45) = 0 |
Thank you.
@ydoom
That was the mistake I was making!! I was executing -trun all the time. i just ran $gcc trun.c -o trun, which perfectly worked!!. I appreciate your help. Thanks for your time. |
All times are GMT -5. The time now is 03:27 AM. |