-4

hope someone can help.

I'm working on a problem set passing arguments in C99 on Ubuntu, part of the problem set specifies that non-integer characters should lead to an early return from the main function and program termination.

For example:

#include <stdio.h>

int main(int argc, string argv[])
{
    // code
}

I've discovered that if I pass the program a ' character at the end of a series of digits e.g. ./runme 12345' it seems to open some kind of shell/prompt.

Can anyone help with what this is?

  • 2
    It's the shell interpreting the quote and expecting you to enter more stuff then a cloing quote. – John3136 Jan 12 '23 at 00:39
  • 1
    Thanks! I'll play about with it and see what happens :) Really interesting actually, closing the quotes means that the integer checking function continues to work as expected even with the quote marks, which it seems aren't evaluated. I'll take the downvotes for the knowledge gained, appreciate it. – user1047228 Jan 12 '23 at 00:40
  • Possible duplicate of [When to wrap quotes around a shell variable](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Jan 12 '23 at 08:21
  • Erm...well part of my problem set is to ensure that non alphanumeric characters are rejected. So this isn't about wrapping a variable it's about me testing my code with deliberately bad input and seeing what happens. – user1047228 Jan 13 '23 at 12:04

2 Answers2

2

This is not related to C, but to your shell. In bash, a single quote has special meaning to the shell, and if you want to pass it to some other program, you have to quote it, for instance

./runme 12345\'

or

./runme "12345'"

This applies of course to all shell meta-characters.

user1934428
  • 19,864
  • 7
  • 42
  • 87
-1

As John3136 wrote in a comment:

It's the shell interpreting the quote and expecting you to enter more stuff then a clo[s]ing quote.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • BTW, if you define in your `.bashrc` for instance `PS2='more input is needed: '` (or whatever text you want to see here), you will get this string printed in such a case, to remind you that the command line is still considered unfinished. – user1934428 Jan 12 '23 at 08:54
  • It's not strictly required, and not my downvote, but when an answer consists only of content written by someone else, it's polite to click the "community wiki" checkbox so you aren't getting reputation from it. – Charles Duffy Jan 12 '23 at 16:04
  • @charles I wasn't even aware this was a thing - in the event that I'm foolhardy enough to ask any more questions (as at this rate I'll be banned from posting for the crime of not knowing ahead of time exactly what's happening on my computer) then I'll be sure to keep this in mind – user1047228 Jan 13 '23 at 12:16