Error message code blocks "no file or directory" - c

I've written and compiled files before but today I receive this error message
dawas-mbp:~ dawasherpa1$ /Users/dawasherpa1/Desktop/Programming 1/Strings/bin/Debug/Strings
-bash: /Users/dawasherpa1/Desktop/Programming: No such file or directory
dawas-mbp:~ dawasherpa1$

There is a space in the directory name "Programming 1", so that with
$ /Users/dawasherpa1/Desktop/Programming 1/Strings/bin/Debug/Strings
the shell tries to execute "/Users/dawasherpa1/Desktop/Programming" with the argument "1/Strings/bin/Debug/Strings". You have to enclose the entire path in quotation marks
$ "/Users/dawasherpa1/Desktop/Programming 1/Strings/bin/Debug/Strings"
or escape the space with a backslash
$ /Users/dawasherpa1/Desktop/Programming\ 1/Strings/bin/Debug/Strings
to execute your program.

First, edit your answer and provide more informations with better language. Your question is hard to read. And what is your platform? Linux?
I see some answers:
do you compiled program before clicked "run"?
have you installed compiler and configured C::B to use it? Click Options and Compiler, check paths.
maybe problem with output directory (chmod 777) ?

Related

c-file cannot be execute in ssh

I work on vsc with remote-ssh. On local side the code works fine, but in ssh I can only compile the code (gcc program.c -o program -std=c11) but when I run it with .\program
I get the error message: bash: .program: command not found
What could be the reason and how can I fix it?
Use ./program. In Bash, and Unix systems generally, the character to separate file system components is the forward slash, “/”. The backward slash, “\” is used to “escape” characters normal purposes and treat the character literally. So \p says to treat “p” as an ordinary “p”, which it already is. So .\program is equivalent to .program, which requests the shell to execute a file named .program. Since there is no such file, it gives you an error message.

Syntax error: word unexpected (expecting ")")

Problem in short - In Linux, whenever we get the following error
"Syntax error: word unexpected (expecting ")")", what does it generally mean?
Problem in details - I have been trying to cross-compile Qt 4.6 as per the Sourcery tool chain on Ubuntu 10.04 (Lucid Lynx). I followed the exact steps mentioned at the link compiling Qt-4.6. But I get the following error right in the ./configure step -
/home/weds/qt-everywhere-opensource-src-4.6.1/bin/qmake: 1: Syntax error: word unexpected (expecting ")")
Searching on the Internet I found lots of posts regarding this error and read all of them. What is this error and how can I solve it?
P.S 1 - the Sourcery toolchain is present inside /opt/ folder and my PATH variable is correctly pointing to it.
P.S 2 - This toolchain was not installed manually by me. Rather it was provided by a vendor as a .tgz file which I extracted inside the /opt/ folder.
That's an error reported by the Almquist shell or any of its derivatives like Dash (and Dash happened to be the default implementation of /bin/sh on Ubuntu 10.04 (Lucid Lynx)) when a word is found while parsing the syntax of a script where a ) is expected instead, for instance like in this case statement:
dash -c 'case a in b c) :; esac'
dash: 1: Syntax error: word unexpected (expecting ")")
That's because after b , the only thing that is expected after is ), (though actually | would also be allowed) so that c word is unexpected.
dash -c 'myfunc( something'
dash: 1: Syntax error: word unexpected (expecting ")")
One case where that can happen is if the script has been written on or transferred through a Microsoft OS where text line endings are CRLF instead of just LF.
A
case a in b) cmd1;;
c) cmd2
esac
script written on MS-DOS would appear as:
case a in b) cmd1;;<CR>
c) cmd2<CR>
esac<CR>
on Unix and that c would be an extra word after the <CR> word.
Here that's unlikely as your error reports the problem being on the first line of the script and most scripts start with the #! /path/to/interpreter shebang line.
Another possibility is that that script you're trying to run has been written on the assumption that sh was bash and uses constructs that are not portable to other sh implementations.
Since you're using an outdated and no longer maintained OS, it's also possible that you're running into a bug in that version of Dash. You could run dpkg-reconfigure dash and tell the system not to use Dash for sh (but Bash instead) to see if that helps.
Again, it is unlikely to be on the first line.
What sounds more likely is that that qmake file is not a script, but a binary executable that is not recognised as such by the system, for instance because it is of a binary format for the wrong architecture or it has been corrupted in transfer.
In that case, when the system fails to recognise it as a native executable, the invoking application would try to run sh on it as if it was a shell script, and the presence of a ( character in the file could cause Dash to fail with such an error.
On my system:
dash /bin/touch
/bin/touch: 1: /bin/touch: Syntax error: word unexpected (expecting ")")
And if you look at the content of /bin/touch as if it were a script, you see:
^?ELF^B^A^A^#^#^#^#^#^#^#^#^#^B^#>^#^A^#^#^#5&#^#^#^#^#^##^#^#^#^#^#^#^#(ô^#^#...
An answer to this seems to be posted in the instructions to which you linked.
Admittedly it's a long way down in the comments but it didn't take long to search for qmake: Syntax error: word unexpected.
Quote:
Tej says: January 4, 2013 at 12:20 pm
Ok, I have solved the Problem. Its very unfortunate that ppl did not
tell what actually is the problem. Problem is we have to use Host
qmake. For that whatever Export (export
PATH=/usr/local/arm/4.3.2/bin:$PATH etc.) we did in step during tslib
installation, we have to undo all of that. Thats it.
Hope that help someone
In case that's not clear, Tej suggests that it would seem that you're trying to run the cross-compiled qmake on the host system.
In 99% of the cases it is a wrong file transfer mode, ASCII or binary.
Try to extract the toolchain directly on the target system.
I was writing a C++ program on Ubuntu 18.04 (Bionic Beaver) when this problem came around. The cause was that the file name of the program contained the characters "(" and ")". After renaming the files, it worked for me.
This error can also be thrown when calling a NodeJS script from a shell script, without providing the correct shebang line in NodeJS:
#!/usr/bin/env node
// Rest of your NodeJS script
A weird fix for me was deleting file package-lock.json and the node_modules folder, and then building the Docker image again.
Sometimes this error occurs just because the directory in which you are currently working has "wrong naming convention" .. like it could be
demo_project (copy)
my_project_1 (another copy)
The correct naming convention says
1. demo_project_copy
2. my_project_1_another_copy

How to execute a C file through cmd

In my current example, I have a C file called 'Main.c' which converts and prints US pounds into UK stones/UK pounds/kilos, and the variable US pounds is currently defined by the user's input (scanf). The file itself is executed through Visual Express 2013; however, I want to change this so that I can navigate to the C file and execute the file directly through the commmand prompt (cmd) whiles passing a value to define US pounds.
I understand that this is required in main:
void main(int argc, char *argv[])
And I know how to navigate to the C file through the command prompt:
>cd Directory/To/The/File
However this is where I get stuck; I don't know how to execute the C file. I have researched into this and found several examples, such as using 'gcc' and 'cc', but the system doesn't recognise these commands. None of the materials that I have found fully explains what exactly I have to do in order to accomplish what I am trying to do; do I have to install something, or am I using the wrong commands, is it possible what I am trying to do, what excactly do I have to do?
Broadly speaking, you need to do the following:
Compile the program using a compiler to generate an executable.
Run the executable file.
When you "run the program in Visual Studio", it is doing all of those steps for you.
I don't know much about command line compiling in Windows, but I believe msbuild is the name of the compiler which Visual Studio uses. Look into that, and you'll see how to compile. Compilation will then generate the executable, which you just type into the command line to run.
EDIT: I found an article which suggests that cl is a C compiler command available on the command line.
Here is the relevant excerpt:
At the command prompt, specify the cl command together with the name of your source file—for example, cl simple.c—and press Enter to compile the program. The cl.exe compiler generates an .obj file that contains the compiled code, and then runs the linker to build an executable program that has the name of your source file, but has an .exe file name extension—for example, Simple.exe.
You cannot cd to the file, only to the directory. The cd command means "change directory".
You cannot execute a C file, it's just a text file and your computer doesn't know how to run it. You need to compile it first (this is what Visual Studio does). There should be an EXE file somewhere close, you need to find it. It is the binary, executable, form of your C program which you can run directly from the command line.

error when i am calling c binary from tcl script

i have created (executable) binary "sample" from .c using
gcc sample.c -o sample
it's created binary named sample sucessfully.
when i run this from terminal like ./sample it display a result..
but when i run this from my tcl like exec ./sample it shows error like ./sample no such file or directory..
can anyone help me to solve the above error?
If sample in the current directory is executable, exec ./sample should work. Assuming that the binary itself does not generate that error message when it runs, of course. (Messages on stderr will become errors in Tcl by default.)
Check that puts [pwd] tells you the place you expected; if you had a cd elsewhere in your script then that relative path would no longer work. If this is the problem, use the full, absolute path to the compiled file. (You can compute this at the start of your script using file normalize sample, but you have to do this before you cd; good library packages do not use cd precisely because it is so confusing while simultaneously being usually totally unnecessary for them…)
If file exists ./sample is true (and file executable ./sample is also true, which it should be if it has just been produced by a compiler) then check immediately after the failed execution what the contents of the errorInfo and errorCode global variables are. They may give a bit more indication of what went wrong. (Or maybe not; can't tell for sure.)

Beginner Doing K&R

I'm just starting programming and going through K&R to try and learn C. I've gotten to the section on command line arguments (5.10) but now I'm stumped. Every time I try and open a program I've written with command line arguments I'm told that file X, X being the argument, doesn't exist.
`gcc -o find find.c
open find test
The file /Documents/Learning_C/test does not exist.`
Any suggestions? Thanks
What system are you on? In Unix/Linux you compile & run your executable via:
gcc -o find find.c
./find test
As others have noted, when you prefix your binary with "./", there wont be any naming conflicts. However, if you made find accessible in your $PATH, you might have some conflicts with find and test--standard programs with most *nix distributions... Maybe you could choose more specific names (i.e. ./myFind testArg)
Try giving your output executable a different name.
I suspect your executing the system find command which is looking for a directory called 'test'.
Or try forcing it by executing
./find toto
Edit: Prepending the ./ to the command is important because it tells the shell to execute the find in the current directory as opposed to the first 'find' that exists in your PATH. It is normally recommended that you don't have . (the current directory) in your PATH for security reasons.
HTH
P.S. Forgot to say good one for working through K&R. I just finished doing the same after working in C for thirty years and it was good to get back and refresh the mind!
Instead of making us all individually guess what exactly you're doing wrong, perhaps you should paste the program you're using for the illustration mentioned ?

Resources