I have the following program: - #include <stdio.h>
-
#include <string.h>
-
#include <stdlib.h>
-
void main ()
-
{
-
char command[20];
-
char *com,*pos,*stack1,*stack2;
-
int boxes,boxtable[25][26],i,j,k,st1,st2;
-
int check=1;
-
for(i=0;i<25;i++){
-
for(j=0;j<26;j++){
-
if(j==0||j==1)
-
boxtable[i][j]=i;
-
else
-
boxtable[i][j]=0;
-
}
-
}
-
scanf("%d",&boxes);
-
gets(command);
-
while(strcmp(command,"quit")!=0){
-
com=strtok(command, " ");
-
stack1=strtok(NULL, " ");
-
pos=strtok(NULL, " ");
-
stack2=strtok(NULL, " ");
-
st1=atoi(stack1+0);
-
st2=atoi(stack2+0);
-
if(st1==st2)
-
check=0;
-
for(i=0;i<boxes;i++){
-
for(j=1;j<=boxes;j++){
-
if(boxtable[i][j]==st1||boxtable[i][j]==st2){
-
for(k=j;k<=boxes;k++){
-
if(boxtable[i][k]==st1||boxtable[i][k]==st2)
-
check=0;
-
}
-
}
-
}
-
}
-
if(check==1)
-
printf("it's true!");
-
gets(command);
-
}
-
for(i=0;i<boxes;i++){
-
for(j=0;j<boxes;j++){
-
printf("%d",boxtable[i][j]);
-
if(j==0)
-
printf(":");
-
printf(" ");
-
}
-
printf("\n");
-
}
-
}
The problem is that using the atoi function makes my program crash after I input the first line (boxes). When I delete the two uses of atoi everything works fine! The problem is I need to convert stack1 and stack2 into integers somehow...any ideas?
2 2207
a problem is -
scanf("%d",&boxes);
-
gets(command);
-
when you type the number followed by newline scanf() returns the number in boxes and the newline is left in the input stream. when gets() is called it returns immediatly with an empty string. try -
scanf("%d",&boxes);
-
getchar(); // remove newline from input stream
-
gets(command);
-
Thanks a lot that solved the problem!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike Moum |
last post by:
I think there may be a bug in string.atoi and string.atol. Here's some
output from idle.
> Python 2.3.4 (#2, Jan 5 2005, 08:24:51)
> on linux2
> Type "copyright", "credits" or "license()"...
|
by: senthil kumar |
last post by:
Hi
We've been noticing a problem with atoi conversion on PowerPC.
When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using...
|
by: Anonymousgoogledeja |
last post by:
Hi all,
since the function atof, atoi, _atoi64, atol returned value are
Return Values
Each function returns the double, int, __int64 or long value produced
by interpreting the input...
|
by: sudharsan |
last post by:
Hi
could you please explain wat atoi( ) function is for and an example
how to use it?
|
by: David Ching |
last post by:
Hello,
I'm a .NET newbie but have 12 years of C++/MFC.
In C++, atoi() stops converting at the first non-digit, so in this code,
octet will be 192:
int octet = atoi("192."); // <-- note...
|
by: sachinahuja82 |
last post by:
Hi
I am using atoi and strtoul in my code.
I have read from MSDN that both functions return 0 if they are
unsuccessful.
i.e strtoul returns 0 if no conversion can be performed.
Now the string...
|
by: pauldepstein |
last post by:
The following description of atoi is pasted from cplusplus.com. My
question is after the pasting.
***** PASTING BEGINS HERE ******
int atoi ( const char * str ); <cstdlib>
Convert string...
|
by: Nezhate |
last post by:
Hi all,
Can you help me? Why this warning appears in the next simple code ?
warning: passing argument 1 of ‘atoi’ makes pointer from integer
without a cast.
#include <stdio.h>
#include...
|
by: Bill Cunningham |
last post by:
I have just read atoi() returns no errors. It returns an int though and
the value of the int is supposed to be the value of the conversion. It seems
to me that right there tells you if there was...
|
by: 66650755 |
last post by:
First,thanks for all who have answered my last question.
if char string="12345";
how could I convert the string(that is "3") to an int by using
atoi? I only want to convert...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |