I need to read parameters from a file called "params", the following is part of codes which can read parameters from that file. But I am not totally understand. Hope anyone can give detailed answers. Thanks.
In a file called "params.c" -
#include "systems.h" /* it includes all .h codes I need */
-
-
int mystrcmp(const char *tag, char *buff)
-
{
-
int l = strlen(tag) ;
-
-
return( strcmp(tag, buff, l) ) ; /* why he uses 3 parameters? I think it should be 2 parameters in "strcmp" ? */
-
-
int params(char *file, int *nx, int *ny)
-
{
-
FILE *fd ;
-
-
fd = fopen(file,"r") ;
-
if ( fd == NULL )
-
{
-
fprintf(stderr, "cannot open %-s\n",file) ;
-
return(1) ;
-
}
-
-
while ( fgets(buff,256, fd ) )
-
{
-
-
if ( mystrcmp("nx", buff) == 0 )
-
sscanf(buff, "%*s %d", nx ); /* what is "%*s" mean? */
-
-
if ( mystrcmp("ny", buff) == 0 )
-
sscanf(buff, "%*s %d", ny );
-
-
fclose(fd) ;
-
return(0) ;
-
}
-
-
}
-
After I compile it ( I do have main funtion, but the probem is here), it shows:
In function ‘mystrcmp’:
"error: too many arguments to function ‘strcmp’ "
warning: passing argument 1 of ‘fgets’ from incompatible pointer type
warning: passing argument 2 of ‘mystrcmp’ from incompatible pointer type
warning: passing argument 1 of ‘sscanf’ from incompatible pointer type
Thank you in advance.
5 4497
strcmp does indeed take two arguments, however, strncmp takes three. sscanf is complaining because your format string is essentially of the form <string> <int>, and the only pointer you're passing in for it to write to is an int*. The * means that the function will scan the data, but not read it in. As to the incompatibility warnings, I'm not completely sure...
strcmp does indeed take two arguments, however, strncmp takes three.
Thanks. it hsould be strncmp.
Do I need to define "buff", if I donot define buff, error message shows "‘buff’ undeclared (first use in this function)". if I define "*buff" as int or float, it will shows the message like:
warning: passing argument 1 of ‘fgets’ from incompatible pointer type
warning: passing argument 2 of ‘mystrcmp’ from incompatible pointer type
warning: passing argument 1 of ‘sscanf’ from incompatible pointer type
How can I define buff coreecty or fgets can give it memory?
Do I need to define "buff"
Of course you do. Why otherwise?
if I define "*buff" as int or float
If you look up the documentation for fgets, you see that buff needs to be a char*. Actually, that translates to buff either pointed to a dynamically allocated char array, or a char array itself. (remember that when you pass a char array[], it decays to a char*)
If you look up the documentation for fgets, you see that buff needs to be a char*. Actually, that translates to buff either pointed to a dynamically allocated char array, or a char array itself. (remember that when you pass a char array[], it decays to a char*)
Thank you. I fix it. Banfa 9,065
Expert Mod 8TB
Thank you. I fix it.
If you are doing that I hope you are allocating some memory for the pointer before writing data to the place it points to.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Justin Carter |
last post by:
Hi. I'm using VB6 and trying to read in a simple text file. I'm
using a statement similar to the following, which generally works
fine.
Input #Item, variable1, variable2, variable3, etc.
...
|
by: franzkowiak |
last post by:
Hello,
I've read some bytes from a file and just now I can't interpret 4 bytes
in this dates like a real value.
An extract from my program
def l32(c):
return ord(c) + (ord(c)<<8) +...
|
by: Alexander Fillips |
last post by:
Hi,
my short question:
is there a python object which can interpret java-script?
the whole story ;-)
I wrote some streaming-scripts for the xbox mediaplayer which supports
python. for a...
|
by: lonelyplanet999 |
last post by:
Hi,
While I'm studying a guestbook processing cgi perl script, I found
below segment commonly found in many illustrating examples of html
form processing.
# GET THE INPUT FROM THE CALLING...
|
by: Fred Ma |
last post by:
I'm using the stringstreams to get the numerical values of string
tokens (the strings result from tokenizing a line of input elsewhere):
#include <iostream>
#include <sstream>
using namespace...
|
by: Robert Bowen |
last post by:
Hello peeplez. I have an odd problem. When I put the ANSI symbol for
"less than" ("<"), the word STRONG and then the ANSI symbol for
"greater than" (">") in my web page, followed by some text, then...
|
by: hup |
last post by:
One of my Linux (CentOS) server stop interpret php code any more. I
did try to compile and installed other version of php, but it's still
not working.
# cat /tmp/phpinfo.php
<?
phpinfo()
?>...
|
by: neerajkumar |
last post by:
Below is the fragment of the filemon utility log.The result is showing DELETE .
After that DKService(diskkeeper) is trying to access the same file.Since i am new to this filemon utility so i dont...
|
by: mailawson |
last post by:
I have this extract from an ASP code which I am trying to adapt for another purpose.
I wish to know what the code in following lines doing in the function chkfunc
stkObj = chk.id.substr(6);...
|
by: Reporter |
last post by:
I got the following example from http://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/index.html
:
echo '<tr><td>First name:</td><td><input type="text" name="first_name"...
|
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: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |