14-12-2004, 08:42 PM
|
#1 (permalink)
|
|
In The Zone
Join Date: Aug 2004
Location: Lucknow
Posts: 246
|
Anybody plz help me with C
Can anyone tell me the syntax 4 using printf n scanf commands in C? Urgent........
__________________
Bitten by the open-source bug...
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
14-12-2004, 09:18 PM
|
#2 (permalink)
|
|
Apprentice
Join Date: Sep 2004
Location: Godless Savage Garden.
Posts: 61
|
Code:
printf ("This is syntax to display text on console");
scanf (&p); //takes value for variable p.
btw, this is the lamest question i have ever seen. you cud have used google or reffered a book instead of starting a whole new thread here. oh well take care of this in future.
__________________
Bother no one. If someone bothers you, ask him to stop. If he does not stop, destroy him.
Visit: http://bodybuilding.name/
|
|
|
14-12-2004, 10:32 PM
|
#3 (permalink)
|
|
Right Off the Assembly Line
Join Date: Dec 2004
Posts: 16
|
Oh!!! Aah!!! I'm Hurt....
i don't like anyone playin' with the code syntaxs' like this......
diabolic the scanf syntax u stated is in-correct 4 a c compliler.....
N U BLUE......Take a look at the online tutorial,
http://cplus.about.com/od/beginnerct.../aa032302a.htm
|
|
|
15-12-2004, 09:49 AM
|
#4 (permalink)
|
|
Broken In
Join Date: Jan 2004
Location: /bin/sh
Posts: 158
|
Code:
printf("text on screen goes here");
scanf("format string", list of variables preceeded with &);
eg scanf("%d",&num);
inputs an integer value in the variable num
|
|
|
15-12-2004, 12:21 PM
|
#5 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
printf() is way too primitive and silly. I have made my own functions that replaces silly printf(), clrscr(), gotoxy(), etc. There are other functions like drawbox(), savescrn(), restscrn(), etc. I have also made a substitute of scanf() and called it get(). But I don't know whether it works properly.
I have a small library of about 40-50 functions that I have made for C. All that you need is a #include statement at the beginning to include the code. I have made a few .h files that may increase convenience. My functions could make coding easier. Concentrate on main logic, not repetitive tasks.
PM me if you want them. BTW, I made them in 1994. So they are pretty old and for Turbo C (under DOS). They may still work. You can try. I suggest have a look. All my code is free and open source  and may be useless now after so many years
|
|
|
15-12-2004, 02:13 PM
|
#6 (permalink)
|
|
In The Zone
Join Date: Jan 2004
Location: somewhere
Posts: 420
|
Buy a good book of C
 Let us C
 Intro to ANSI C by Balaguruswamy
__________________
[ॐ एसएमएस॰सोल्भर ॐ]
|
|
|
15-12-2004, 03:23 PM
|
#7 (permalink)
|
|
Broken In
Join Date: May 2004
Location: Kolkata
Posts: 197
|
"Let us C" is a good book for the beginners, who doesn't know anything except the name "C". Seeing the pattern of your question, I'm sure thats the right book for you! Anyhow, I didnt like the book by Balaguruswamy at all. My suggestion is, once you are versed with the sintaxes, if you are still interrested and really want to learn C, then go for C by Herbert Schildt.
@diabolique: The scanf function, as already mentioned is incorrect. And, some compilors don't allow the space between the printf and the"( )".
@tuxfan: I'd really like to see what you've had done with the libraries, I'll PM you my mail id and if its not too much please send me those files!
__________________
Hard work never killed anybody..........But why take the RISK
|
|
|
15-12-2004, 06:11 PM
|
#8 (permalink)
|
|
Right Off the Assembly Line
Join Date: Mar 2004
Posts: 39
|
any book on c could have helped you out
|
|
|
16-12-2004, 11:44 AM
|
#9 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
I have received a few PMs for the functions  I am really glad
I think it will be convenient for me to upload it somewhere and offer for download from there rather than sending it by email to everyone.
Please give me some time. I will upload it and post a link for download.
But please let me make it clear that they were made under DOS. Good for learning, but may be not of any practical use under Windows environment. But I may be wrong.
|
|
|
16-12-2004, 11:52 AM
|
#10 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
Here's a description of functions kept at the beginning of the functions source. Some of they may be really useless, but I got carried away at that time
Quote:
|
Originally Posted by my C lib
/*
***************************************
* Functions included in the library *
***************************************
co-ordinates are in Clipper format i.e. row,col
************************************************** ***********************
drawbox() savescrn() restscrn() prntscrn()* scroll()
caps() num() scrolock() insert() caps_p()*
num_p()* scrol_p()* insert_p()* rshift_p() lshift_p()
alt_p() ctrl_p() reboot()* file() inkey()
space()* replicate()* abs()* ltrim() rtrim()
midtrim() isalpha()* isupper()* islower()* isdigit()*
row() col() setcursor() getcursor() basememory()*
say() clear() fcomp() clrkeybuff() newcolour()
isprint() print() eject() resetprint() disptime()
setvduaddr() shell() keyboard() seconds() sscrn_file()
rscrn_file()
************************************************** ***********************
þ void drawbox(t,l,b,r,string,colour)
* t = TOP, l = LEFT, b = BOTTOM, r = RIGHT
String of 1 character = string of 9 same characters.
First 8 characters draws the box, 9th character fills
it. If string of only 8 characters just draws the box.
þ char *savescrn(t,l,b,r)
* usage <char *var> = savescrn(l,t,r,b)
þ void restscrn(t,l,b,r,scrn)
þ void prntscrn()
* #include <dos.h>
þ void scroll(t,l,b,r,sp)
* #include <dos.h>, scroll screen contents a specified no of lines
þ int caps(cmd)
* usage <int var> = caps(cmd)
cmd = 0 turns it off
cmd = 1 turns it on
cmd = 2 returns current status
<int var> = 1 => ON
<int var> = 0 => OFF
þ int num(cmd)
* usage <int var> = num(cmd)
cmd = 0 turns it off
cmd = 1 turns it on
cmd = 2 returns current status
<int var> = 1 => ON
<int var> = 0 => OFF
þ int scrolock(cmd)
* usage <int var> = scrolock(cmd)
cmd = 0 turns it off
cmd = 1 turns it on
cmd = 2 returns current status
<int var> = 1 => ON
<int var> = 0 => OFF
þ int insert(cmd)
* usage <int var> = insert(cmd)
cmd = 0 turns it off
cmd = 1 turns it on
cmd = 2 returns current status
<int var> = 1 => ON
<int var> = 0 => OFF
þ int caps_p()
* usage <int var> = caps_p(), if capslock kept pressed
<int var> = 1 => ON
<int var> = 0 => OFF
þ int num_p()
* usage <int var> = num_p(), if numlock kept pressed
<int var> = 1 => ON
<int var> = 0 => OFF
þ int scrol_p()
* usage <int var> = scrol_p(), if scrolllock kept pressed
<int var> = 1 => ON
<int var> = 0 => OFF
þ int insert_p()
* usage <int var> = insert_p(), if insert kept pressed
<int var> = 1 => ON
<int var> = 0 => OFF
Note : Pressing <Insert> terminates the wait state
created by getch(), getche(), etc.
þ int rshift_p()
* usage <int var> = rshift_p(), if rightshift kept pressed
<int var> = 1 => Right Shift pressed
<int var> = 0 => Right Shift not pressed
þ int lshift_p()
* usage <int var> = lshift_p(), if leftshift kept pressed
<int var> = 1 => Left Shift pressed
<int var> = 0 => Left Shift not pressed
þ int alt_p()
* usage <int var> = alt_p(), if alt kept pressed
<int var> = 1 => Alt pressed
<int var> = 0 => Alt not pressed
þ int ctrl_p()
* usage <int var> = Ctrl_p(), if ctrl kept pressed
<int var> = 1 => Ctrl pressed
<int var> = 0 => Ctrl not pressed
þ void reboot()
* #include <dos.h>
þ int file(*string)
* usage <int var> = file(*string)
*string = pointer to filename with full path
<int var> = 1 => exist
<int var> = 0 => does not exist
þ int inkey(unsigned int)
* usage <int var> = inkey(noofsec), wait for a key press
þ void space(var,noofsp)
* var should defined as an array of length noofsp+1
otherwise it may give unpredictable result
þ void replicate(var,noofsp,ch)
* var should defined as an array of length noofsp+1
otherwise it may give unpredictable result
þ int absolute(num)
* usage <int var> = absolute(<int var>)
þ char *ltrim(string)
þ char *rtrim(string)
þ char *midtrim(string)
þ int isalpha(ch)
* usage <int var> = isalpha(string[0])
<int var> = 1 => alphabet
<int var> = 0 => not an alphabet
þ int isupper(ch)
* usage <int var> = isupper(string[0])
<int var> = 1 => upper case alphabet
<int var> = 0 => lower case alphabet or not an alphabet
þ int islower(ch)
* usage <int var> = islower(string[0])
<int var> = 1 => lower case alphabet
<int var> = 0 => upper case alphabet or not an alphabet
þ int isdigit(ch)
* usage <int var> = isdigit(string[0])
<int var> = 1 => digit
<int var> = 0 => not a digit
þ int row()
* #include <dos.h>
usage <int var> = row()
<int var> + 1 = row set by gotoxy()
because first position is 1 in gotoxy() and not 0
þ int col()
* #include <dos.h>
usage <int var> = col()
<int var> + 1 = column set by gotoxy()
because first position is 1 in gotoxy() and not 0
þ void setcursor(t,b)
* #include <dos.h>
Start scan line < 0 and start scan line > 13 puts cursor off
Start scan line between 0 and 13 AND End scan line < 0
or End scan line > 13 gives a full block cursor
þ int getcursor(cmd)
* usage <int var> = getcursor(cmd)
cmd = 1 receive start scan line
cmd = 2 receive end scan line
þ int basememory()
* #include <dos.h>
usage <int var> = basememory()
<int var> = number of kilo bytes
þ void say(r,c,*string,colour)
* #include "colour.h"
r = ROW c = COLUMN
Displays a string and not a single character
þ void clear(t,l,b,r)
* Advantages over clrscr()
1. It can clear a part of the screen
2. It sets the attribute bytes to NORMAL i.e. 7
þ int fcomp(name1,name2)
* usage <int var> = fcomp(fname1,fname2)
<int var> = -1 => error opening files
<int var> = 0 => files are not same
<int var> = 1 => files are same
þ void clrkeybuff(), clears keyboard buffer
þ void newcolour(t,l,b,r,colour), just changes the color of specified characters, useful for see-thru shadow
* #include "colour.h"
þ int isprint()
* #include <dos.h>
usage <int var> = isprint()
<int var> = 1 => printer ready
<int var> = 0 => printer not ready
þ void print(string,arg1,arg2)
* #include "print.h"
þ void eject()
* #include "print.h"
void print();
int isprint();
þ void resetprint()
* #include "print.h"
void print();
þ void disptime(row,col,colour)
* #include "print.h"
#include <dos.h>
void say()
þ void shell()
* #include <process.h>
#include <stdio.h>
þ void keyboard(int ascii,int scan)
* #include <dos.h>
þ long unsigned seconds()
* #include <dos.h>
usage <long unsigned var> = seconds()
þ void sscrn_file(char *filename)
* #include <stdio.h>
þ void rscrn_file(char *filename)
* #include <stdio.h>
*/
|
|
|
|
17-12-2004, 02:54 PM
|
#11 (permalink)
|
|
Right Off the Assembly Line
Join Date: Sep 2004
Posts: 44
|
syntax
syntax for your printf:-
printf("control string",variable);
eg:-
printf("sum=%d",num);
syntax for your scanf function
scanf("input string",&variable);
eg:-
scanf("%d",&num);
/* num is a variable such as int num */
|
|
|
20-12-2004, 02:03 PM
|
#12 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
Sorry for the delay in making my code available. I spoke to GNUrag and he says that even if it is very insignificant piece of code, it must be released in the right way. I am working under his guidance and will let everyone know when the code will be available.
|
|
|
23-12-2004, 06:59 PM
|
#13 (permalink)
|
|
In The Zone
Join Date: Aug 2004
Location: Lucknow
Posts: 246
|
Thankx.....
I wanted to thank you all for the help....sorry to tell u but i do program in C++.....a friend of mine wanted codes in C so I tried my hands on it....I suppose thats not a reason enough 4 buyin a book.....and if I had 2 buy a book....Y would I ask it on the forum????
NEwayz....I wanted to know how to work with long integers n floating point nos. ....I mean the scanf statement needed 4 doin that.....NE BODY?????
__________________
Bitten by the open-source bug...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|