::links not allowed, please read the Posting Guidelines::
The function readit() seems to jump to writeit() when it shouldn't in read.c This has got me stumped. After inside the readit() gets called it seems to when the function ends it seems to just process the writeit() when it isn't being called. Any help would be much appreciated :P
10 1770
I know the checkbuff() function is lame that's why it isn't being used.
sicarie 4,677
Recognized Expert Moderator Specialist
I know the checkbuff() function is lame that's why it isn't being used.
Can we see a snippet of your code? The useful parts would probably be the declarations and the implementations of those functions, maybe a line or two before and after.
Well i will post 2 pages
It seems to be when the readit() gets called, it just jumps and writeit() gets processed
-------READ.C---------------- - #ifndef filesize
-
#define filesize 2001
-
#endif
-
-
struct tmpcommands{
-
FILE *fp;
-
};
-
-
extern void filehelp_text(char file[]){
-
printf("\nFILE FUNCTIONS: ");
-
printf("\nUsage is %s <COMMAND> <FILE> -f \n", file);
-
printf("Commands are -read, -append, -write, -delete\n");
-
printf("Remember the -f flag must be activated to use the file functions\n");
-
}
-
-
-
-
extern void readit(char file[]){
-
char filedata[80];
-
struct tmpcommands init;
-
init.fp = fopen(file, "r");
-
while(fgets(filedata, 80, init.fp)!=NULL)
-
printf("%s\n", filedata);
-
fclose(init.fp);
-
}
-
-
-
extern void writeit(char file[]){
-
char filedata[80];
-
struct tmpcommands init;
-
-
if(init.fp = fopen(file, "r"))
-
if(init.fp != NULL){
-
int hasbofprotect = 0;
-
char writedata[filesize];
-
char bofprotect[filesize];
-
fprintf(stdout, "The file contains data,\nplease enter some data to create the file and save the text\n");
-
fclose(init.fp);
-
init.fp = fopen(file, "w");
-
fscanf(stdin, "%s", &writedata);
-
-
if(strlen(writedata) >= filesize){
-
fprintf(stdout, "Error max file size length is 2000 bytes\n you entered %d bytes\n", strlen(writedata));
-
fprintf(stdout, "Please enter some text, remember max file size is 2000 bytes. :P\n");
-
fscanf(stdin, "%s", &bofprotect);
-
fprintf(init.fp, "%s", bofprotect);
-
hasbofprotect = 1;
-
}
-
-
if(hasbofprotect == 0){
-
fprintf(init.fp, "%s", writedata);
-
fprintf(stdout, "Everything is wrote to the file.\n");
-
fclose(init.fp);
-
}
-
-
}
-
else
-
{
-
char writedata[filesize];
-
-
-
-
fprintf(stdout, "You have chosen to write some data into the file: %s.\n", file);
-
-
-
}
-
}
-
-
extern void appit(char file[]){
-
char filedata[80];
-
struct tmpcommands init;
-
}
-
-
-
-
#ifdef filesize
-
#undef filesize
-
#endif
----MAIN.C----------- - #include <stdio.h>
-
#include <string.h>
-
#include <stdlib.h>
-
#include "main.h"
-
#include "safe.c"
-
#include "read.c"
-
-
/* checkbuff(buffer); A little command i made to check for bof in text which can be quite usefull */
-
-
static void command(char command[commandlen], char file[20], char flag[2]){
-
struct tmpcommands issue;
-
char com[10];
-
int iffile = 0;
-
-
if(strcmp(flag, "-f") != 1)
-
iffile = 1;
-
-
if(iffile != 0){
-
if(strcmp(command, "-read") != 1)
-
readit(file);
-
-
if(strcmp(command, "-write") != 1)
-
writeit(file);
-
-
if(strcmp(command, "-append") !=1)
-
appit(file);
-
-
}
-
}
-
-
-
int main(int argc, char *argv[]){
-
-
/* Main variables */
-
char buffer[max_buff];
-
char proccommand[commandlen];
-
int i=0;
-
-
if (argc < 4 ){
-
-
filehelp_text(argv[0]);
-
fprintf(stdout, "I am busy adding more commands, this program is still under development\n\n");
-
return 1;
-
-
}
-
-
command(argv[1], argv[2], argv[3]);
-
-
-
return 0;
-
}
if(strcmp(comma nd, "-read") != 1)
readit(file);
if(strcmp(comma nd, "-write") != 1)
writeit(file);
if(strcmp(comma nd, "-append") !=1)
appit(file);
This is not good programming style. strcmp() returns a value of 0 when the comparison is equal and a value <0 when command is less than the second srgumennt. Both of these are !=1.
So if command is "-append", that's less than "-read", you you call readit().
Then "-append" is less than "-write" so you call writeit().
Then "-append" is equal to "-append" so you call appit().
Do you mean: -
if(strcmp(command, "-read") != 0)
-
readit(file);
-
-
if(strcmp(command, "-write") != 0)
-
writeit(file);
-
-
if(strcmp(command, "-append") !=0)
-
appit(file);
-
???
This is not good programming style. strcmp() returns a value of 0 when the comparison is equal and a value <0 when command is less than the second srgumennt. Both of these are !=1.
So if command is "-append", that's less than "-read", you you call readit().
Then "-append" is less than "-write" so you call writeit().
Then "-append" is equal to "-append" so you call appit().
Do you mean: -
if(strcmp(command, "-read") != 0)
-
readit(file);
-
-
if(strcmp(command, "-write") != 0)
-
writeit(file);
-
-
if(strcmp(command, "-append") !=0)
-
appit(file);
-
???
Well..... I thought strcmp returned 0 if the comparison is equal. I have changed it to !=0 and this is the result
doskey@DosKeys-Xion-sys:~/Desktop/project/src$ gcc main.c -o test
doskey@DosKeys-Xion-sys:~/Desktop/project/src$ ./test -read c -f
doskey@DosKeys-Xion-sys:~/Desktop/project/src$ ./test -read c -fa
The file contains data,
please enter some data to create the file and save the text
kjh
Everything is wrote to the file.
For some reason the -f flag needs another byte.... actually you can use any two bytes like -ba as an arguement. Also as you can see, when i used -read it still skipped and went to the writeit(). No matter what i put -append, -read, -write it's always jumping to the writeit() function.
This is the modified command() function -
static void command(char command[commandlen], char file[20], char flag[2]){
-
struct tmpcommands issue;
-
char com[10];
-
int iffile = 0;
-
-
if(strcmp(flag, "-f"))
-
iffile = 1;
-
-
if(iffile == 1){
-
if(strcmp(command, "-read")!=0)
-
readit(file);
-
-
if(strcmp(command, "-write")!=0)
-
writeit(file);
-
-
if(strcmp(command, "-append")!=0)
-
appit(file);
-
-
}
-
}
-
As you can see this program is doing stuff it hasn't been programmed to do.
I NEED HELP !!!!!!!!
How about you try: -
if(strcmp(command, "-read") == 0)
-
readit(file);
-
-
if(strcmp(command, "-write") == 0)
-
writeit(file);
-
-
if(strcmp(command, "-append") ==0)
-
appit(file);
-
My apology that I didn't see this on my previous post.
It seems it doesn't work. I don't know where i am going wrong here? HELP !!!!
Your problem is somewhere else. I took this code and made some stub functions and hard-coded a command. I then changed the command, recompiled. Each time I got the correct results: only one function was called. -
void readit()
-
{
-
cout << "readit" << endl;
-
}
-
void writeit()
-
{
-
cout << "writeit" << endl;
-
}
-
void appit()
-
{
-
cout << "appit" << endl;
-
}
-
int main()
-
{
-
char command[] = "-append";
-
if(strcmp(command, "-read") == 0)
-
readit();
-
-
if(strcmp(command, "-write") == 0)
-
writeit();
-
-
if(strcmp(command, "-append") ==0)
-
appit();
-
-
}
-
That's C++, you can't use C++ in your C code :S
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Margaret MacDonald |
last post by:
I'm seeing a problem that has me flummoxed. The only thing I can
think of is that I'm violating some rule I don't know about.
I have some code that does some processing and then does a
header('Location: ...) jump to page A on success or falls through to
the jump to page B. This is the code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) )
{
mysql_query( $q, $link ) ; // store the record
|
by: Sam Wuebben |
last post by:
I've been trying to get the values of hidden fields from one of many
forms on a page to load into a function.
The test page is at: http;//www.mvldesign.com/test/item_pop.html
The 'Add to Cart" image needs to send that forms data to the function
seen in the head.
Firebird's javascript Console states that "form has no properties"
|
by: JKop |
last post by:
Take the following simple function:
unsigned long Plus5Percent(unsigned long input)
{
return ( input + input / 20 );
}
Do yous ever consider the possibly more efficent:
|
by: brianj7675 |
last post by:
Basically i'm trying to write a previous next link in order to go to
the next page in my database(similar to google's with numbers in the
middle for pages the user wants to jump to.
My only thought is i'm losing the parameters on page reload.
But if that is the case then I don't know the correct technique to keep
the variables
I am programming in php but using a javscript function with onclick.
I could use $_SESSION variables to retain...
|
by: anonymous |
last post by:
Thanks your reply.
The article I read is from
www.hakin9.org/en/attachments/stackoverflow_en.pdf.
And you're right. I don't know it very clearly. And that's why I want
to understand it; for it's useful to help me to solve some basic
problem which I may not perceive before.
I appreciate your help,
sincerely.
| |
by: baumann |
last post by:
hi all,
typedef int (*pfunc)(int , int);
pfunc a_func;
i know it's ok,
but how can define a_func without typedef statement?
thanks .
|
by: Todd A. Anderson |
last post by:
I have a function foo of which I need to get the address. The problem
is that when you say "&foo" (or just foo for that matter), you get the
address of this function's entry in a jump table and not the address of
the function itself. Are there any BKMs for getting the real address or
am I going to have to write a function that looks to see whether the
address is a jump instruction and if so compute the real address from
the jump target?...
|
by: A Wieser |
last post by:
Hello,
It seems something's going on with regard to the way Visual Studio 2005
implements function pointers.
Once upon a time, it was possible to have unmanaged code as follows:
__declspec(naked) void HookJump(...)
{
_asm
|
by: =?Utf-8?B?bGlhbnF0bGl0?= |
last post by:
Is using a jump statement more faster than using if statement
with a jump statement
example
for(int i=0; i < 10; i++)
{
if(a == null)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |