Code: Select all
int my_input;
...
scanf(" %d", &my_input);
Code: Select all
#include <stdheaders.h>
int main(void){
int inches;
int revolutions;
int sprockets;
printf("Inches:");
scanf("%d",inches);
revolutions = inches / 25;
sprockets = revolutions * 4;
printf("sprockets %d",sprockets);
}You need to pass the address of "inches", not it's value. Look at Hal's example again.printf("Inches:");
scanf("%d",inches);
int scanf (const char *template, ...)
The scanf function reads formatted input from the stream stdin under the control of the template string template. The optional arguments are pointers to the places which receive the resulting values.
The return value is normally the number of successful assignments. If an end-of-file condition is detected before any matches are performed, including matches against whitespace and literal characters in the template, then EOF is returned.
Code: Select all
scanf("%d",&inches);
versus
printf("sprockets %d",sprockets);

Code: Select all
#include <stdheaders.h>
#define STRBUF 20 /* or whatever */
int main(void)
{
int inches;
int revolutions;
int sprockets;
char readLine[STRBUF];
printf("Inches:");
fgets(readLine, STRBUF*sizeof(char), stdin);
sscanf(readLine, "%d", &inches);
revolutions = inches / 25;
sprockets = revolutions * 4;
printf("sprockets %d", sprockets);
}
sscanf is not secure because it may cause buffer underruns. I think your program might not be very security relevant, but don't get used to sscanf.voidengineer wrote:Then consider trying sscanf![]()

Code: Select all
...,STRBUF*sizeof(char), ... Or just use whatever suits _you_.voidengineer wrote:Please pay your respects to the people that bring you linux, and the men that created C, and make tabstops 8 spaces please.
I think you're wrong with that statement.Azazel_7 wrote:And if you really want to have a good compiler, try coding in your gentoo and run gcc, as lcc is only an adaption of it for windows.
Sorry, my mistake. Mixed-up accidently lcc and cygwin... So you're right.Genone wrote:I think you're wrong with that statement.Azazel_7 wrote:And if you really want to have a good compiler, try coding in your gentoo and run gcc, as lcc is only an adaption of it for windows.