PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label getchar. Show all posts
Showing posts with label getchar. Show all posts

Monday, October 31, 2022

[FIXED] Why does the Linux(?)-Terminal not "consume" '\n' EOF?

 October 31, 2022     c, eof, getchar, stdin, terminal     No comments   

Issue

From what I've read, the Linux terminal (in default settings) buffers the input and only sends it after receiving either EOF or '\n'.

When I loop c = getchar(); and check each c for being EOF (end then break) I need to do CTRL-D twice in order to stop reading, as the first EOF is always consumed by the terminal (I know one can change the terminal to raw, but maybe this is a bit overkill).

However, when I check for c being '\n' (which also sends the input) it will not be consumed.

Example:

  • Input: "abc\n"
    • Characters read: 'a','b','c','\n'
  • Input: "abc" and Ctrl-D
    • Characters read: 'a','b','c'
  • Input: "abc", Ctrl-D and Ctrl-D again
    • Characters read: 'a','b','c',EOF
  • Input: "abc", Return and Ctrl-D
    • Characters read: 'a','b','c','\n',EOF

Isn't this highly inconsistent? Or is there any rationale behind it?

I want to parse input including whitespaces and thus cannot check for '\n' but for EOF - is that possible without changing the terminal to raw?

I've tried with feof(stdin) too, but apperently this doesn't work either :/


Solution

That's not how it works. ^D sends on the currently buffered line, so if you don't hit it immediately after a newline, your program will not see an empty read and will not know the input is ended. So you need another ^D to send nothing. But your program never sees a ^D.

In fact you can use stty to change the terminal's EOF character, so that for example ^N will end the input; your program will run exactly the same, because it does not depend of the value of the EOF keyboard character.

PS. Since you were trying to write a C program: the input calls return EOF when they try to read a file, and get an empty buffer (0 characters). In fact, EOF is not ^D as you imagine, but -1: This value was chosen because it does not fit in a byte, while read() could legally return any possible byte (yes, even '\04' aka ^D). This is why the signature of getchar() says it returns an int.



Answered By - alexis
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How i can stop reading values after EOF

 October 31, 2022     c, eof, getchar, stdin     No comments   

Issue

I have little problem with my code. I try to make 'while' loop which will read all my input values and then stop when i clicked EOF. I have read that EOF in windows is CTRL+Z and so on but my 'while' doesn't want to stop and after all input values and CTRL+Z, it stay and wait for next values. This is my code and hope you will help me thanks):

#include <stdio.h>
#include <stdbool.h> 

#define gc getchar



inline int scan_integer();
inline void zaprzeczenie(bool*);


int main() {
  bool rosnie=true;

  int poprzednia;
  register int terazniejsza;


  terazniejsza = scan_integer();
  poprzednia = terazniejsza;

  int sumaAktualnego=terazniejsza;
  int sumaNajwiekszego=terazniejsza;

  int iloscAktualnego=1;
  int iloscNajwiekszego=0;

  int staly=1;
  int sumaStalego=0;


  while(!feof(stdin))
  {
    printf("%d ",terazniejsza);
    terazniejsza = scan_integer();


    if(terazniejsza<poprzednia){
        if(rosnie){
            if(iloscAktualnego>iloscNajwiekszego){
                iloscNajwiekszego=iloscAktualnego;
                sumaNajwiekszego=sumaAktualnego;
            }
            iloscAktualnego=1;
            sumaAktualnego=terazniejsza;

            if(staly>1){
                iloscAktualnego+=staly;
                sumaAktualnego+=sumaStalego;
                staly=1;
                sumaStalego=0;
            }

            zaprzeczenie(&rosnie);
        }
        else{
            sumaAktualnego+=terazniejsza;
            iloscAktualnego++;
        }
    }
    else if(terazniejsza>poprzednia){
        if(rosnie){
            sumaAktualnego+=terazniejsza;
            iloscAktualnego++;
        }
        else{
            if(iloscAktualnego>iloscNajwiekszego){
                iloscNajwiekszego=iloscAktualnego;
                sumaNajwiekszego=sumaAktualnego;
            }
            iloscAktualnego=1;
            sumaAktualnego=terazniejsza;

            if(staly>0){
                iloscAktualnego+=staly;
                sumaAktualnego+=sumaStalego;
                staly=1;
                sumaStalego=0;
            }

            zaprzeczenie(&rosnie);
        }
    }
    else if(terazniejsza==poprzednia){
        staly++;
        sumaStalego+=poprzednia;
        sumaStalego+=terazniejsza;
        sumaAktualnego+=terazniejsza;
        iloscAktualnego++;
    }

    poprzednia=terazniejsza;
}
  if(iloscAktualnego>iloscNajwiekszego){
      iloscNajwiekszego=iloscAktualnego;
      sumaNajwiekszego=sumaAktualnego;
  }

  printf("%d %d",iloscNajwiekszego, sumaNajwiekszego);
 }

 inline int scan_integer()
{
  register int c = gc();
  int wejsciowa = 0;
  for( ; ((c<48 || c>57)); c = gc() );

  for( ;c>47 && c<58; c = gc() ) {
      wejsciowa = (wejsciowa << 1) + (wejsciowa << 3) + c - 48;
  }
  return wejsciowa;
}

inline void zaprzeczenie(bool* boo){
  boo=!boo;
}

P.S.:Sorry for polish variables)


Solution

#define gc getchar

Please don't do this - it makes it harder for others to read and understand your code.

while( !feof( stream )) doesn't work the way most people expect it to, and will wind up looping one too many times. Instead, you need to check the result of your last input operation. Since you're using getchar, you can check the result of that:

while ( (terazniejsza = scan_integer()) != EOF )
{
  ...
}

...

inline int scan_integer()
{
  register int c = gc();
  int wejsciowa = 0;
  for( ; ((c<48 || c>57) && c != EOF ); c = gc() );

  for( ;c>47 && c<58 && c != EOF; c = gc() ) {
      wejsciowa = (wejsciowa << 1) + (wejsciowa << 3) + c - 48;
  }
  return c != EOF ? wejsciowa : c;
}    


Answered By - John Bode
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, October 30, 2022

[FIXED] How to exit stdin when EOF is reached in C programming

 October 30, 2022     arrays, c, eof, getchar, stdin     No comments   

Issue

I'm having troubles with my program. The aim of it is to read an input of numbers from the user, and when they stop inputting numbers (ctrl-d) it collects the inputted numbers and prints out 'Odd numbers were: blah blah' and 'Even numbers were: blah blah'.

I'm having trouble with how to exit the program at EOF and when it feels like I have overcome that problem, another problem occurs which is my program doesn't print the numbers from the array. It only prints 'Odd numbers were:' and 'Even numbers were:'.

Any help is appreciated. Thanks

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void) {
int n, i, array[1000];
    i=0;
    while (i = getchar() !=EOF) {
        scanf("%d", &array[i]);
        i++;
    }   
    printf("Odd numbers were:");
    i=0 ;
    while(i = getchar() != EOF) { 
        if(array[i]%2!=0) {
            printf(" %d", array[i]);
            i++;
        }
    }
    printf("\nEven numbers were:");
    i=0 ;
    while(i = getchar() !=EOF) { 
        if (array[i]%2==0) {
            printf(" %d", array[i]);
            i++;
        } 
    }
        printf("\n");
return 0;
}

Solution

Performing Single-Digit Conversion to int

You may be making things a bit harder on yourself than it needs to be. While you can use while (scanf ("%d", &array[i]) == 1) to read whitespace separated integers and avoid having to perform a manual conversion, if your intent is to read single-digits, then using getchar() is fine. (for that matter, you can read any multi-digit integer with getchar(), it is simply up to you to provide a conversion from the ASCII characters to final numeric value)

The manual conversion for single-digit characters is straight forward? When you read digits as characters, you are not reading the integer value represented by the digit, you are reading the ASCII value for the character that represents each digit. See ASCII Table and Description. In order to convert a single ASCII character digit to it's integer value, you must subtract the ASCII value of '0'. (note: the single-quotes are significant)

For example if you read a digit with int c = getchar();, then you need to subtract '0' to obtain the single-digit integer value, e.g. int n = c - '0';

When filling an array, you must ALWAYS protect against writing beyond the bounds of your array. If you declare int array[1000] = {0}; (which has available zero-based array indexes of 0-999), then you must validate that you never write beyond index 999 or Undefined Behavior results. To protect your array bounds, simply keep track of the number of indexes filled and test it is always below the number of array elements available, e.g.

while (n < MAX && (c = getchar()) != EOF)   /* always protect array bounds */
    if ('0' <= c && c <= '9')               /* only handle digits */
        array[n++] = c - '0';               /* convert ASCII to int */

Next, while you are free to test n % 2 (using the modulo operator), there is no need (little endian). Since any odd number will have its ones-bit set to 1, all you need is a simple bitwise comparison, e.g (7 in binary is 0111).

    if (array[i] & 1)                       /* if ones-bit is 1, odd */
        printf (" %d", array[i]);

Of course, for even numbers, the ones-bit will be 0 (e.g. 8 in binary is 1000), so the corresponding test can be:

    if ((array[i] & 1) == 0)                /* if ones-bit is 0, even */
        printf (" %d", array[i]);

Putting all of the pieces together, you can store all single digits read in array and then segregate the even and odd numbers for printing in a very simple manner (note: neither stdlib.h or math.h are required),

#include <stdio.h>

#define MAX 1000   /* define a constant rather than use 'magic' numbers in code */

int main (void)
{
    int array[MAX] = {0},
        c, i, n = 0;

    while (n < MAX && (c = getchar()) != EOF)   /* always protect array bounds */
        if ('0' <= c && c <= '9')               /* only handle digits */
            array[n++] = c - '0';               /* convert ASCII to int */

    printf ("\narray        : ");               /* output array contents */
    for (i = 0; i < n; i++)
        printf (" %d", array[i]);

    printf ("\narray - odd  : ");
    for (i = 0; i < n; i++)
        if (array[i] & 1)                       /* if ones-bit is 1, odd */
            printf (" %d", array[i]);

    printf ("\narray - even : ");
    for (i = 0; i < n; i++)
        if ((array[i] & 1) == 0)                /* if ones-bit is 0, even */
            printf (" %d", array[i]);

    putchar ('\n');                             /* tidy up w/newline */

    return 0;
}

Example Compilation with Warnings Enabled

$ gcc -Wall -Wextra -pedantic-std=gnu11 -Ofast -o bin/arrayevenodd arrayevenodd.c

Example Use/Output

$ echo "01234567890123456789" | ./bin/arrayevenodd

array        :  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
array - odd  :  1 3 5 7 9 1 3 5 7 9
array - even :  0 2 4 6 8 0 2 4 6 8

Look things over and let me know if you have further questions.


Performing Manual Multi-Digit Conversion to int

If you are needing to convert multi-digit integers from characters, the easy way is to use a function that provides the conversion for you (e.g. the scanf family of functions or by using line oriented with fgets or getline and parsing and converting the strings of digits with strtok and then strtol, or parsing with sscanf, etc.)

However, performing a manual conversion of individual characters read by getchar() into a multi-digit integers is straight forward. You simply check for a valid character than can begin an integer (including the prefixes of +/-) and sum each digit providing a proper offset for the place of the digit by increasingly multiplying the sum by 10 before adding (or actually subtracting if building a the sum as a negative sum for coding efficiency purposes) each digit until you reach the next non-digit and then you add the final sum to your array and advance the array index.

While building the sum, it is up to you to check for integer Overflow before adding the final sum to your array. (you can handle the overflow condition however you like, the example below just throws the error and exits)

The manual conversion probably adds about 20 lines of code, e.g.

#include <stdio.h>
#include <stdint.h> /* exact length types */
#include <limits.h> /* INT_X constants */

#define MAX 1000    /* define constant rather than use 'magic' number in code */

int main (void)
{
    int array[MAX] = {0},
        c, i, start = 0, sign = 1, n = 0;
    int64_t sum = 0;

    while (n < MAX && (c = getchar()) != EOF) { /* always protect array bounds */
        if (!start) {                           /* flag to start building int  */
            start = 1;                          /* flag - working on int */
            if (c == '+')                       /* handle leading '+' sign */
                continue;
            else if (c == '-')                  /* handle leading '-' sign */
                sign = -1;
            else if ('0' <= c && c <= '9')      /* handle digits */
                sum = sum * 10 - (c - '0');     /* note: sum always computed */
            else                                /*       as negative value   */
                start = 0;                      /* reset - char not handled  */
        }
        else if ('0' <= c && c <= '9') {        /* handle digits */
            sum = sum * 10 - (c - '0');         /* convert ASCII to int */
            if (sum < INT_MIN || (sign != -1 && -sum > INT_MAX))
                goto err;               /* check for overflow, handle error */
        }
        else {                          /* non-digit ends conversion */
            if (sum)                    /* if sum has value, add to array */
                array[n++] = sign != -1 ? -sum : sum;
            sign = 1;                   /* reset values for next conversion */
            start = 0;
            sum = 0;
        }
    }
    if (sum)    /* add last element to array on EOF */
        array[n++] = sign != -1 ? -sum : sum;

    printf ("\narray        : ");               /* output array contents */
    for (i = 0; i < n; i++)
        printf (" %d", array[i]);

    printf ("\narray - odd  : ");
    for (i = 0; i < n; i++)
        if (array[i] & 1)                       /* if ones-bit is 1, odd */
            printf (" %d", array[i]);

    printf ("\narray - even : ");
    for (i = 0; i < n; i++)
        if ((array[i] & 1) == 0)                /* if ones-bit is 0, even */
            printf (" %d", array[i]);

    putchar ('\n');                             /* tidy up w/newline */

    return 0;

    err:

    fprintf (stderr, "error: overflow detected - array[%d]\n", n);
    return 1;
}

Example Use/Output

$ echo "1,2,3,5,76,435" | ./bin/arrayevenodd2

array        :  1 2 3 5 76 435
array - odd  :  1 3 5 435
array - even :  2 76

Example with '+/-' Prefixes

$ echo "1,2,-3,+5,-76,435" | ./bin/arrayevenodd2

array        :  1 2 -3 5 -76 435
array - odd  :  1 -3 5 435
array - even :  2 -76

Look over the new example and let me know if you have any more questions.



Answered By - David C. Rankin
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why do I need to include EOF in my loop condition?

 October 30, 2022     c, eof, getchar, while-loop     No comments   

Issue

I have been given a task to write a program that will take keyboard input (excluding space) and print to a .txt file without using an array.

I tried to use a while loop to do this but was getting an infinite loop, I then came on to stack overflow and found a solution within a different problem, EUREKA!

Adding:

&& ch != EOF 

solved my problem.

However, I do not fully understand why the solution works and would like help to understand why this second condition was needed.

while((ch=getchar()) != '\n' && ch != EOF)
   {
       putc(ch, fin);
   }
   fclose(fin);
   return 0;

Thank you.


Solution

Because the return value of getchar is the character read on success, and EOF on error or when the end-of-file has been reached:

man getchar

RETURN VALUE

fgetc(), getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error.

There are several reasons as to why stdin might reach end-of-file:

  • The user pressed Ctrl+D (on Unix/Linux) which causes stdin to close
  • stdin was connected to a pipe ($ cat file.txt | ./myprogram) and the pipe closed because cat ended.
  • stdin was connected to a redirection ($ ./myprogram < file.txt) and it reached the end of file.txt

On all this cases, getchar will eventually return EOF and you cannot keep reading. If you do

while((ch=getchar()) != '\n')
{
    ...
}

and stdin closes, then you end up in an endless loop, als EOF != '\n' always evaluates to true. So in order to protect yourself from that, you have to check if the read operation failed. And you do that by checking whether the reading function returned EOF. That's why

int ch;
while((ch=getchar()) != '\n' && ch != EOF)
{
    ...
}

is the correct way of looping with getchar. Also note that ch must be of type int.

Note also that this applies for all FILE buffers (opened in read mode), not only to stdin.



Answered By - Pablo
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What will be EOF here in the below code?

 October 30, 2022     ascii, c, character, eof, getchar     No comments   

Issue

I was reading the C programming language book and in the given below code I am not quite getting how will we be getting an EOF here? And also I don't exactly get what is an EOF? is it a character, integer or a condition? If it is a condition then please explain. Thank you.

#include <stdio.h>
int main(int argc, char *argv[]){
int c;
while((c = getchar()) != EOF){
  printf("%d", c != EOF);
  putchar(c);
}
printf("\n%d\n", c != EOF);
}

Solution

The getchar function can return any possible character that can be represented on your system, plus one more, additional, special, "out-of-band" return value indicating that there are no more characters to be returned. This value is referred to by the symbolic macro identifier EOF. Somewhere behind <stdio.h> there is typically a definition like

#define EOF (-1)

The value isn't necessarily -1, but that will serve our purposes. (We don't have to know or care what the actual value is, because we always refer to EOF, insulating us from the actual value.)

Whatever value EOF has, it's guaranteed not to be the same as any actual character. So if getchar returns a value other than EOF, it's an actual character that has been read. But if it returns EOF, that's the indication that the input stream has reached end-of-file, that there are no more characters to be read.

So EOF is most definitely not a character. It is an integer, with a value different than any char. I wouldn't call it a "condition", although it you test for it, using code like

if(c == EOF)

or

if(c != EOF)

I would say that those expressions c == EOF and c != EOF are conditions.

It's especially confusing because typically there's a special character you can type on the keyboard to generate an end-of-file indication. On Windows it's control-Z; on Unix and other systems it's control-D. But this does not mean that EOF is control-Z on a Windows system or that it's control-D on a Unix system. Those characters are handled by the terminal driver and translated into an indication that, after several additional levels of handling and interpretation, causes getchar to return EOF. But one way to prove that EOF is not control-Z or control-D is to observe that when you're using getchar or getc to read from a file, you get an EOF indication at end-of-file even though there's no one typing control characters at a keyboard in that case.

Finally, this discussion reminds us of the importance of using int variables to carry the values returned by getchar. The code you cited correctly declared

int c;

and then used the variable c to hold the values returned by getchar. Why use an int here? Since getchar returns characters, and since c is a character, wouldn't it make more sense to declare

char c;

That seems like it makes sense, but it's actually quite wrong. Type char can hold any character the system can represent. But remember, getchar can return any character value, plus the EOF value. If you assign getchar's return value to a variable of type char, you end up "scraping off" the EOF indication, by inadvertently mapping it to an actual character value. What happens next is either that you map an actual character (usually ÿ) to EOF and mistakenly stop reading when you read one, or that you map EOF to an actual character and so never detect it and so go into an infinite loop instead of stopping at end-of-file.



Answered By - Steve Summit
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why do I need to type Ctrl-D twice to mark end-of-file?

 October 30, 2022     c, eof, getchar     No comments   

Issue

char **query; 
query = (char**) malloc ( sizeof(char*) );

int f=0;
int i=0,j=0,c;


while((c=getchar())!=EOF)
{      
    if(!isalpha(c))
        continue;

    if(f==1)
        query=(char**) realloc(query,(i+1)*sizeof(char*));

    query[i]=(char*) malloc(sizeof(char));
    query[i][j]=c;
    j++;


    while( (c=getchar())!=EOF&&c!=' '&&c!='\t' )
    {      

        query[i]=(char*) realloc(query[i],(j+1)*sizeof(char));

        query[i][j]=c;
        ++j;
    }   

    query[i][j]='\0';
    printf("%s\n",query[i]);
    if(c==EOF){

        break;
    }   

   ++i;
   f=1;
   j=0;
}

I want the above code snippet to read a line of strings separated by spaces and tabs until ONE EOF but it requires 2 EOFs to end the loop. Also, strings can consist of only alphabetic characters.

I am struggling on about 2 days. Please, give some feedback.

EDIT: Most probably the reason is I hit CTRL+D keys after I write last string not the enter key, but now I hit enter and then CTRL+D, it works as expected. But, how can I change it to finish after I hit CTRL+D once following the last string?


Solution

On Unix-like systems (at least by default), an end-of-file condition is triggered by typing Ctrl-D at the beginning of a line or by typing Ctrl-D twice if you're not at the beginning of a line.

In the latter case, the last line you read will not have a '\n' at the end of it; you may need to allow for that.

This is specified (rather indirectly) by POSIX / The Open Group Base Specifications Issue 7, in section 11, specifically 11.1.9:

EOF
Special character on input, which is recognized if the ICANON flag is set. When received, all the bytes waiting to be read are immediately passed to the process without waiting for a <newline>, and the EOF is discarded. Thus, if there are no bytes waiting (that is, the EOF occurred at the beginning of a line), a byte count of zero shall be returned from the read(), representing an end-of-file indication. If ICANON is set, the EOF character shall be discarded when processed.

The POSIX read() function indicates an end-of-file (or error) condition to its caller by returning a byte count of zero, indicating that there are no more bytes of data to read. (C's <stdio> is, on POSIX systems, built on top of read() and other POSIX-specific functions.)

EOF (not to be confused with the C EOF macro) is mapped by default to Ctrl-D. Typing the EOF character at the beginning of a line (either at the very beginning of the input or immediately after a newline) triggers an immediate end-of-file condition. Typing the EOF character other than at the beginning of a line causes the previous data on that line to be returned immediately by the next read() call that asks for enough bytes; typing the EOF character again does the same thing, but in that case there are no remaining bytes to be read and an end-of-file condition is triggered. A single EOF character in the middle of a line is discarded (if ICANON is set, which it normally is).



Answered By - Keith Thompson
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how to create each word of input to start a new line

 October 30, 2022     c, eof, getchar, putchar     No comments   

Issue

Hey i am trying to print each word on a new line. My EOF is also not working and was wondering why this is. i have made it to scan for a space and then print new line.

#include <stdio.h>
#include <ctype.h>

int main(void)
{
    char ch;

    while ((ch = getchar()) != '#')
        putchar(ch);

int nextChar;
    nextChar = getchar();
    while (nextChar != '\n' && nextChar != EOF);
    {
        if (ch== ' ')
        {
            printf("\n");
        }
        else
        {
            putchar(ch);
        }
        {
            ch = getchar();
        }
        printf("\n");

        {
            scanf("%lc",&nextChar);
            printf("%c",nextChar);
        }

        return 0;
    }
}

just for example input: Stackoverflow is great
output:
Stackoverflow
is
great


Solution

You should REALLY start enabling compiler warnings. They can help you find many bugs. Look here when I compile with -Wall and -Wextra.

$ gcc ba.c -Wall -Wextra
ba.c: In function ‘main’:
ba.c:13:5: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
     while (nextChar != '\n' && nextChar != EOF);
     ^~~~~
ba.c:14:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
     {
     ^

Remove the ; after the while loop.

But there are other problems too. As you can see from when I corrected the indentation for you, the return 0 statement is inside the while loop. I assume that's not what you want.



Answered By - klutt
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to simulate an EOF?

 October 30, 2022     c, eof, getchar, kernighan-and-ritchie     No comments   

Issue

I am currently reading K&R's book and typing in the examples from the first section, and there are a couple of examples such as this:

while((c = getchar()) != EOF) {
    //do something
}

I am testing these examples on a Windows box and thus running the compiled exe files from the cmd prompt.

To test the example above, how do I simulate an EOF? That is, basically how can I make the loop stop when testing the example from the command prompt?


Solution

To enter an EOF, use:

  1. ^Z (CtrlZ) in Windows
  2. ^D on Unix-like systems


Answered By - Greg Hewgill
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing