Home » Archimedes archive » Acorn User » AU 1995-06.adf » !C_C » c/gets

c/gets

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1995-06.adf » !C_C
Filename: c/gets
Read OK:
File size: 01F9 bytes
Load address: 0000
Exec address: 0000
File contents
/* C for Yourself - Acorn User June 1995
   Demonstration of the differences between scanf() and gets()
   by Steve Mumford */

#include <stdio.h>

void
main(void)
{
    char string[100];

    printf("Please enter a string consisting of several words:\n");
    gets(string);
    
    printf("Your string was: ");
    puts(string);

    printf("\nNow enter the same phrase to see what scanf() makes of it:\n");
    scanf("%s",string);
    printf("\nscanf() stored the string: %s",string);
   
    return;
}
00000000  2f 2a 20 43 20 66 6f 72  20 59 6f 75 72 73 65 6c  |/* C for Yoursel|
00000010  66 20 2d 20 41 63 6f 72  6e 20 55 73 65 72 20 4a  |f - Acorn User J|
00000020  75 6e 65 20 31 39 39 35  0a 20 20 20 44 65 6d 6f  |une 1995.   Demo|
00000030  6e 73 74 72 61 74 69 6f  6e 20 6f 66 20 74 68 65  |nstration of the|
00000040  20 64 69 66 66 65 72 65  6e 63 65 73 20 62 65 74  | differences bet|
00000050  77 65 65 6e 20 73 63 61  6e 66 28 29 20 61 6e 64  |ween scanf() and|
00000060  20 67 65 74 73 28 29 0a  20 20 20 62 79 20 53 74  | gets().   by St|
00000070  65 76 65 20 4d 75 6d 66  6f 72 64 20 2a 2f 0a 0a  |eve Mumford */..|
00000080  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
00000090  68 3e 0a 0a 76 6f 69 64  0a 6d 61 69 6e 28 76 6f  |h>..void.main(vo|
000000a0  69 64 29 0a 7b 0a 20 20  20 20 63 68 61 72 20 73  |id).{.    char s|
000000b0  74 72 69 6e 67 5b 31 30  30 5d 3b 0a 0a 20 20 20  |tring[100];..   |
000000c0  20 70 72 69 6e 74 66 28  22 50 6c 65 61 73 65 20  | printf("Please |
000000d0  65 6e 74 65 72 20 61 20  73 74 72 69 6e 67 20 63  |enter a string c|
000000e0  6f 6e 73 69 73 74 69 6e  67 20 6f 66 20 73 65 76  |onsisting of sev|
000000f0  65 72 61 6c 20 77 6f 72  64 73 3a 5c 6e 22 29 3b  |eral words:\n");|
00000100  0a 20 20 20 20 67 65 74  73 28 73 74 72 69 6e 67  |.    gets(string|
00000110  29 3b 0a 20 20 20 20 0a  20 20 20 20 70 72 69 6e  |);.    .    prin|
00000120  74 66 28 22 59 6f 75 72  20 73 74 72 69 6e 67 20  |tf("Your string |
00000130  77 61 73 3a 20 22 29 3b  0a 20 20 20 20 70 75 74  |was: ");.    put|
00000140  73 28 73 74 72 69 6e 67  29 3b 0a 0a 20 20 20 20  |s(string);..    |
00000150  70 72 69 6e 74 66 28 22  5c 6e 4e 6f 77 20 65 6e  |printf("\nNow en|
00000160  74 65 72 20 74 68 65 20  73 61 6d 65 20 70 68 72  |ter the same phr|
00000170  61 73 65 20 74 6f 20 73  65 65 20 77 68 61 74 20  |ase to see what |
00000180  73 63 61 6e 66 28 29 20  6d 61 6b 65 73 20 6f 66  |scanf() makes of|
00000190  20 69 74 3a 5c 6e 22 29  3b 0a 20 20 20 20 73 63  | it:\n");.    sc|
000001a0  61 6e 66 28 22 25 73 22  2c 73 74 72 69 6e 67 29  |anf("%s",string)|
000001b0  3b 0a 20 20 20 20 70 72  69 6e 74 66 28 22 5c 6e  |;.    printf("\n|
000001c0  73 63 61 6e 66 28 29 20  73 74 6f 72 65 64 20 74  |scanf() stored t|
000001d0  68 65 20 73 74 72 69 6e  67 3a 20 25 73 22 2c 73  |he string: %s",s|
000001e0  74 72 69 6e 67 29 3b 0a  20 20 20 0a 20 20 20 20  |tring);.   .    |
000001f0  72 65 74 75 72 6e 3b 0a  7d                       |return;.}|
000001f9