🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #394

Re: Default input value in C

#394
From: Dan Akunis
Date: Sun, 10 Jan 1999 00:00
69 lines
2363 bytes
Here is the C code for your BASIC script:

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
  {
    char x[50],text[50]="This is default text";
    int  x1=0,amount=50;
    printf("\n");
    printf("Enter something if you like!  <%s> ",text);
    gets(x);
    if (strlen(x))
      strcpy(text,x);
    printf("Enter a value <%d> ",amount);
    scanf("%d",&x1);
    if (x1 != 0)
      amount=x1;
    printf("\n");
    printf("The value of text$ now = %s\n",text);
    printf("The amount = %d\n",amount);
    getch();
  }











mbt4w <DontlikeSpam@overthere.com> wrote in article
<36990041.3BADD052@overthere.com>...
> Hi,
> 
> I would like to allow defaults to user input in C. 
> I'm using Borland C++ 4.52 on Win98. I'm trying to learn 
> standard C programming or has close as possible even though 
> I'm using a C++ package.   It seems the input commands I've 
> tried so far will not allow an 'empty' entry. 
> 
> What I would like to happen is :
> � Prompt the user for an input while displaying a default entry
> � If the user presses only the enter key use the default entry
> � If another value was entered, used it.
> 
> Below is a basic program that does this. 
> How do I do it in C?
> 
> text$ = "This is default text"
> amount = 50
> PRINT
> PRINT "Enter something if you like! <"; text$; "> ";
> INPUT x$
> IF x$ <> "" THEN text$ = x$
> PRINT "Enter a value. <"; amount; "> ";
> INPUT x
> IF x <> 0 THEN amount = x
> PRINT
> PRINT "The value of text$ now = "; text$
> PRINT "The amount ="; amount
> 
> 
> Thanks
> 
Technical Details
Message-ID: <01be3ce3$e7d21460$1f3585c2@default>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36990041.3BADD052@overthere.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f8d38,6ac36e1493d03328
X-Google-Attributes: gidf8d38,public
X-Google-Thread: 161995,6ac36e1493d03328
X-Google-Attributes: gid161995,public
X-Google-Thread: 114592,6ac36e1493d03328
X-Google-Attributes: gid114592,public
From: "Dan Akunis" <akunis@glx.chief.co.il>
Subject: Re: Default input value in C
Date: 1999/01/10
Message-ID: <01be3ce3$e7d21460$1f3585c2@default>
X-Deja-AN: 431011366
References: <36990041.3BADD052@overthere.com>
X-Complaints-To: postmaster@ibm.net
X-Trace: news.ibm.net.il!ibm.net 916005316 30542 (none) 194.133.53.31
Organization: Unspecified Organization
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.os.msdos.language