jephthah 1,888 Posting Maven

it's about Ethics, not Morals

and if you think Ethics aren't a HUGE issue in today's business world, you surely have been living in a cave. hell, I have to study an entire section on Ethics in order to take my PE (professional engineer's) Exam.

but whatever, it's clear you were not kidding. so you're either exposing yourself as a liar, or you're just covering your tracks because you're scared. I'll give you the benefit of the doubt and assume the latter.

Now anyhow, where were we .... oh, yes. we've addressed the double backslash filename issue (\\), so what other questions do you have :)

.

jephthah 1,888 Posting Maven

...

i'd be sooo very thankful if u could code this part for me in C asap. ... please can u do it in an hour or so ? please give it a try.

...

am seriously ready to pay a reasonable amount for this... around $20 ... i need to submit tomorrow.


dude... i'm not going to make threats, but this looks pretty incriminating to me. and it's worse than cheating on homework, you were offering to pay us to help you cheat on your final semester project.

you need to think about this.

your problem is trivial and you could have had all the help you needed and then some, if you would have just come in without the hysterics.

but rather than take responsibility and work it out like everyone else, you've gone and compromised your academic integrity. I'm not going to spend the time to track you down and turn you in ... but you'll know. and you'll remember this day.

my screen name is a legendary figure who did the same thing: Panicked right before leading a major battle, and promised God he would make a sacrifice of a member of his household if he could get help to defeat his enemies. Now, Jephthah could have won the battle without divine intervention, but by trying to game the system, he wound up having to make his only daughter a burnt offering. Judges 11:29-40, …

jephthah 1,888 Posting Maven

no offence. i'm a student and that all i can afford

that's why we HELP for FREE.

don't you have some sort of academic integrity policy at your school? I'm sure paying for homework is in violation of that.

i just turned in someone to their engineering dean and course professor for this.

jephthah 1,888 Posting Maven

$20? LOL. we don't want your spare change. we'll help you for free. but only if you're ready to do the work. you couldnt afford us, otherwise.

jephthah 1,888 Posting Maven

when are we going to get colored icon for each post that has been up-repped or down-repped?

when are we going to get visible representation people who are so lousy, that they've been downvoted into the negative?

jephthah 1,888 Posting Maven

Look. here's your first hint. you do NOT reinstall your OS every time something difficult or confusing occurs.

i mean, seriously, just THINK about that.

now did you write the file1.c to the directory in the first place? what happens when you try to do it again? any warnings?

is your directory write-protected? find a file in that directory and "touch" it. any warnings?

do an "ls -l" command on the directory itself to see the owner and group permissions. use "chown" or "chmod", respectively, to change them if they're not what they should be. use the "su" or "sudo" command if you need to increase your own permission to do so.

.

jephthah 1,888 Posting Maven

goodlord, do NOT reinstall your OS. and you're wasting your time with g++ unless you want to compile C++ (.cpp) files. the simple fact is just that your gcc is obviously not able to see your file1.c, and there has to be a simple explanation.

do this:

first type " pwd " and <enter>
then type " ls -l *.c " and <enter>
then type " gcc -o file1 file1.c " and <enter>

one after another, in teh same window, without doing anything else, and cut and paste the entire results (command and response) here.

jephthah 1,888 Posting Maven

don't get hung up on the details of fgets() right now if it causes you to get too far ahead of your class instruction. to use it without understanding it could get you in trouble with your instructor that they might accuse you of plagiarizing someone else's solution.

if your instructor is expecting you to use scanf(), you can use it to get a string input like so: scanf("%s", color1); .... with one big "however":

most programmers don't recommend using scanf() for getting string input -- it's very prone to having all sort of bad behavior. I'm one of those people who dislike scanf(). i don't think it should be taught to new students at all.

but it is. and if it helps you to move past the string input issue for now, and concentrate on getting "the rest of your program" working... then go for it.

just be advised, what AIA posted about fgets() is the recommended way to do it, as it offers the most safety for the least cost.


.

jephthah 1,888 Posting Maven

[pseudocode]

get 'number'

do outer loop while 'number' > 9

   set value of 'sum' to zero

   do inner loop for each 10's place digit in 'number'

      increment 'sum' by value of each digit in 'number' 

   replace 'number' with this 'sum'

'number' is now sum of digits reduced to a single digit

[/pseudocode]

jonsca commented: Thanks for using pseudocode tags +4
jephthah 1,888 Posting Maven

'=' is an assignment operator
'==' is a comparison operator

do you want to assign a value
or compare two values

jephthah 1,888 Posting Maven

actually, i think my response was kinder than a simple "no".

:)

jephthah 1,888 Posting Maven

theres no way i'm going to copy all that code into files on my local drive and then debug it for you.

start with one error at a time. trace the line that it calls out and fix the problem. then recompile. repeat.

you'll often find a lot of seemingly-unrelated errors will disappear once you fix one thing.

if you're stuck, post the single error and the *relevant* code. not your entire project dump.

we generally suggest fixes for you based on sight. we generally do not compile and trace your code through a debugger. if we can't read your code easily, it's likely to be ignored.

this is not peculiar to this website, it's generally standard behavior in any programming help forum. most people who will help you here are professionals or serious students who have other demands on their time

Aia commented: Kindly put. +8
jephthah 1,888 Posting Maven

walt is right. you are confusing plagiarism with theft.

whether he will, at some point the future, properly attribute the source in his paper... that is both unknown and irrelevant.

what he wants, right now in the present, is for someone to violate copyright law and give him for free what anyone else would have to pay for.

IANAL, but i'm pretty certain that's a form of theft. conspiracy to commit theft, anyhow.

jephthah 1,888 Posting Maven

in most countries it will be unimaginable to put in the same ONE plane the most important persons in the country...

yes, that was terrible. condolences. :(

still, as tragic as it was, the same could have theoretically happened in America. the President and First Lady, some senior military and a handful of congressmen could all be on Air Force One. It wouldn't have incapacitated the government over here any more than it did for you there.

the end result is your tragedy was caused by human factors. We like to think our pilots are more competent and less likely to make that error, but on a bad day it could have happened to us.

jephthah 1,888 Posting Maven

no... I'm a student

if you're a masters candidate, then i think it's about time you get familiar with your university's library.

i can't imagine a university, even in a Second World country, that is unable or unwilling to make journals and standards documents accessible to students.

jephthah 1,888 Posting Maven

dude, you suck.

seriously, coming in here trying to wheedle your way into getting someone to steal the property of someone else, and then give it to you, just so you can continue to weasel your way to a dubious "masters degree" ?

WTF ever. I say, you work for some crappy software consulting gig, and they want you to steal a copy of it because they don't want to pay for it.

really, now go sit somewhere quiet and think about your life for a while.

jephthah 1,888 Posting Maven

and for those of you following along at home: The C Standard (as of 2005: C99, TC1, and TC2) confirms.

impressive.

jephthah 1,888 Posting Maven

what's the problem?

this function converts a numeric IP address into a "dotted decimal" string for human readability.

here's the specification:
http://www.opengroup.org/onlinepubs/000095399/functions/inet_ntop.html

and here's a more user friendly reference:
http://beej.us/guide/bgnet/output/html/multipage/inet_ntopman.html

jephthah 1,888 Posting Maven

maybe he got his mod status revoked :P

jephthah 1,888 Posting Maven

the text is most likely not formatted in any meaninful way and fscanf will be difficult if not impossible to use.

use fgets() to read the file line by line.
use strtok() to parse each element (or token) in the line by delimiting each element by the spaces (' ')
use strtol() to determine if element is an integer and convert it

jephthah 1,888 Posting Maven

initialize a float with value zero.
begin a while loop to take character input, and break on newline entered.
in the body of the while loop you will :
--- check if decimal point is entered. if so, keep track of this fact, and continue to get next character
--- convert numeric char to value
--- if value is prior to decimal point, multiply total float value by 10, then add the numeric value
--- if after the decimal point, divide the numeric value by incrementing powers of 10, add the result to the total float value

you will need to perform error checking at all inputs, to ensure no invalid characters are entered.

jephthah 1,888 Posting Maven

are u sure?i mean what is dim2size and why isn't there dim1size??also my array includes only characters inside...can u transform my code so that the function will return the array?

well have you tried it??

look:

void sin1(char map[][MAX_COLS])

make your prototype and your definition like this. you only have to declare the size of the second index. in the main function, pass in the map directly to your function without recasting it: sin1(map); because it already is a pointer (to an array).

and no, you dont want to try and return the array. pass it by value as an argument as shown.

jephthah 1,888 Posting Maven

well, you don't have a return value.

but i dont know if that's the source of your error code. i don't use Dev C++ so I can't say. I use CodeBlocks (w/ MinGW on windows) or gcc (on linux).

I do recommend CodeBlocks, because it's my preference. I've heard criticisms of Dev-C++ that there are some various compile-related issues, but I've also heard people who love it.

It is important to note that DevC++ hasnt been updated since 2005, despite numerous complaints (many of which may have been user error). CodeBlocks stable release was 2 years ago.

If you try CodeBlocks, be sure to get the binary that includes MinGW.


EDIT: that reminds me... did you get the DevC++ version that comes with MinGW? if you didnt, then who knows how it's being compiled. that could cause the error.

jephthah 1,888 Posting Maven

But... the compiler return always zero.

the compiler is not returning zero. the compiler is what builds your code into a binary executable after linking the appropriate functions from teh standard libraries. the binary (program) is thing that, during runtime, returns your values of zero or otherwise.

so, you know, I'm just sayin'.

otherwise ... what Salem says ^


.

jephthah 1,888 Posting Maven

line 4

*ptr2Data = (unsigned long) SomeArrayOfData[4];

jephthah 1,888 Posting Maven

sorry it took me so long to get back to this.. You should learn how to use strtol(). each time you call strtol, it finds the first numeric value in a string, converts it to a long int and returns it. it sets the pointer argument to the very next character in that string

if non-numeric characters (alpha or symbols) are found, zero is returned as the value and the pointer continues to point at the start of the string that was being looked at. this indicates that it failed to find a numeric in the string.

(Note, strtol() will ignore and skip over any whitespace found before a value. whitespace after an int value indicates the end of that value.)

i'm going to give you this snippet because i think seeing an example like this in action is really instructive.

// ... set up your variables

fgets(single_line, sizeof(single_line), stdin)

numberOfEntries = strtol(single_line, &ptr, 10)

for (i = 0; i < numberOfEntries ; i++)

   value[i] = strtol(ptr, &ptr, 10) 

// ... do the rest

some people may think i'm giving you too much, so you're going to need to figure out from here how to set it up properly within the context of your program.

Be advised this performs no error checking whatsoever; erroneous input may cause this code to behave quite badly. all good code should have error checking.

for reference:
fgets()
strtol()


.

jephthah 1,888 Posting Maven

Sorry about the lack of the proper programming style.

I've just started learning programming and I'm not been really taught the proper way to do it.

yeah, and i was a little overly-bitchy. overall, you're on the right track: everyone has to learn somewhere, and "proper coding style" comes mostly with experience.

so, don't stress it too much. you're doing as well as a beginner should be expected. just keep it in mind that "readable code" is just as important as "working code". here's a few general principles:

-- make your variable names meaningful. don't be afraid to use long variable names. use capital letters and/or underscores to make multi-word variable names.

-- use #defines to name your "magic numbers", rather than just sticking them in the code with the hope that you'll remember what they mean 6 months later.

-- there's no single "best" bracketing style, but you do need to pick one bracketing style and always stick with it. don't mix it up.

-- make judicious use of whitespace to separate code functionality.

-- learn to make you code modular by creating subroutines that do particular tasks, rather than lumping everything under main()

Would this be a lot better?

not especially. fundamentally this is the same thing. any differences are matters of degree.

it still uses "magic numbers" that are cryptic and error-prone, variable names that are similarly meaningless to the reader, and is still a huge string of code that …

jephthah 1,888 Posting Maven

Hi. first a comment, then the answer:

the reason why it took 14 hours for someone to reply, is that your code is nearly unreadable. yes, you used code blocks and yes you used indentations, and that's a great start. thank you.

but your lack of a consistent style of bracketing, lack of a consistent style of indentation, and a seeming aversion to using whitespace or giving your variables meaningful names, well, all of that makes it very hard to understand what you're doing.

and if you think this is a pedantic criticism, it's not. unreadable code is worthless in the industry, even if it "works". companies lose millions of dollars and people lose jobs because code is not intelligible to others.

so, i felt sorry for you not getting an answer, but i had to fix your code to make it readable before i could spot the the (very simple) error.

here's your newly formatted code. merry christmas:

#include <stdio.h>
#include <time.h>

int main(void)
{

    int x, y[12][12] = {{0},{0}};
    int roll, move;

    int i, j;               // okay, these are loop indexes
    int a, b, c, d;         // but these are meaningless names here

    srand(time(NULL));

    a=5;
    b=5;
    y[5][5]=003;         // "magic numbers" are not good programming


    {  // <--- WHY IS THIS BRACKET HERE?

        for(i=1; i<=10;i++)
        {
            y[1][i] = 2;          // more magic numbers
            if(i==5 || i==6)      // okay, it just gets worse from here.
                y[1][i] = 0;      // so no more comments about …
tux4life commented: Nice :) +8
jephthah 1,888 Posting Maven

before i start trying to explain it, i need to understand what exactly the requirements are.

i see you tried to explain, above, but i apologize that i don't fully understand what you said,

jephthah 1,888 Posting Maven

Ctrl z is not a C function. IOW, the interpretation of ctrl-z is system dependent, and is not necessarily EOF. For example, on unix, ctrl-d is used as EOF. On systems where ctrl-z is used, it still doesn't always get interpreted as eof, as you have seen

for microsoft OS, ctrl-z is only EOF when it is found at the beginning of the input stream. in this case EOF is a negative value (-1). when ctrl-z is found in the middle of an input stream after text, it is interpreted as a non-printable ascii character, just like any other escaped character. in this case:

ctrl-a = 0x01
ctrl-b = 0x02
...
ctrl-z = 0x1A

you can test it yourself by trying different combinations of text and control characters. remember the printf() is blocking and will buffer the standard input until a newline is entered, so you'll have to hit <enter> after any given amount of text.

#include <stdio.h>

int main() {
    int c;

    while (1)
    {
        putchar(c = getchar());
        printf(" %c = %#X\n",c,c);
    }
    return 0;
}
popcorn99 commented: leet h4x0r +0
kvprajapati commented: helpful. +9
jephthah 1,888 Posting Maven

you can probably do it with scanf() in a complex and obscure and difficult-to-understand manner.

i don't know how.

but i do know how to do it with fgets() and atoi() in a simple, straightforward and easily-understood maner..

jephthah 1,888 Posting Maven

The problem is that it is not reading in any zero's. I manually traced the program and discovered that the bug lies in this section of presults.c

while(wt >= 1)
        {       /*  get msd, convert to char, and print it  */
                #ifdef DISPLAY
                write_char(int_to_dig(sig_dig_value(ans,wt)));
                #else
                putchar(int_to_dig(sig_dig_value(ans,wt)));
                #endif
                /*  strip the msd  */
                ans = supress_msd(ans,wt);
                /*  go on to next weight  */
                wt = weight(ans);
        }

Okay, dude.....

I AM REALLY REALLY SORRY for hijacking your thread to go off on some ranting tangent that has been mostly unhelpful

really, I am sorry. I don't know WTF my problem was. Your code, once i got over the fact that it uses some non-standard libraries (horrors!) , is actually very clearly written, very nicely formatted, and very easy to understand

your problem is both simple and sneaky.

the fact is that when you have a zero in a power of 10's place, the modulus does not care that it's there.

so 305 only finds the 3 and the 5.

if you use integer division like you're doing to find the Weight, you will always have this problem.

the good news is, you really only need to call the weight function once, to get the highest power of 10. every power for the remaining digits is just one less power of 10. you dont need to calculate it, just decrement each time after the initial calculation:

while(wt >= 1)
        {       /*  get msd, convert …
jephthah 1,888 Posting Maven

try this, this does the weight according to your function...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include "presults.h"

main()
{
    /* Declare variables */
    int integer, valid, i;
    char weight[16], numStr[16], suppress_msd[16];  // oversized

    /* Prompt user for input */
    printf("Enter integer: ");

    /* While there are more integers at input */

    while( scanf("%d", &integer) <= 0)   // <--- NOTE, DON'T USE EOF!
    {
         /* Print a blank line */
         printf("\n");

         /* Update loop */
         printf("Enter integer: ");
    }

    /* convert integert to string */
    sprintf(numStr,"%d",integer);


    /* suppress msd and get weight, whatever this means */
    weight[0] = numStr[0];      // the single msd character, 
                                // copy to start of 'weight' string

    // get the weight which is the msd multiplied by the base power of 10.
    // then add a NULL character at the end to form a string

    for (i=1; i < strlen(numStr); i++)
        weight[i] = '0';   // note the difference between the zero '0' (ASCII 0x30)

    weight[i] = '\0';  // and the NULL '\0' (ASCII 0x00) characters

                                
    strcpy(suppress_msd, &numStr[1]);  // copy the rest of number 
                                       // to the 'suppresss_msd' string

    printf("\nYour number was %d.\n\"weight\" is %s, \"suppress msd\" is %s\n\n", 
                                                     integer, weight, suppress_msd);

}
jephthah 1,888 Posting Maven

sorry for the confusion.. here is the fixed version of my wild attempt at this.

Now I'm sure this isn't anything like what you need for your assignment, but it's just an example of how you could approach this without using the non-standard library functions.

#include <stdio.h>
#include <string.h
#include <stdlib.h>
//#include "presults.h"

main()
{
/* Declare variables */
int integer, valid;
char weight[3];                        // for two digits
char numStr[16], suppress_msd[16];     // oversized
char *ptr;                             // for the strtol() function


/* Prompt user for input */
printf("Enter integer: ");

/* While there are more integers at input */

while( scanf("%d", &integer) <= 0)   // <--- NOTE, DON'T USE EOF!
{
     /* Print a blank line */
     printf("\n");

     /* Update loop */
     printf("Enter integer: ");
}

/* convert integert to string */
sprintf(numStr,"%d",integer);


/* suppress msd and get weight, whatever this means */
weight[0] = numStr[0];      // the single msd character, 
                            // copy to start of 'weight' string
                            
strcpy(suppress_msd, &numStr[1]);  // copy the rest of number 
                                   // to the 'suppresss_msd' string


// you want your weight (apparently) multiplied by 10 
// so add another zero character '0' to the end.   then add a null 
// character after that to terminate the array and form a string.

weight[1] = '0';   // note the difference between the zero '0' (ASCII 0x30)
weight[2] = '\0';  // and the NULL '\0' (ASCII 0x00) characters


/* it doesnt get any simpler */
printf("\nYour number was %d.\n\"weight\" is %s, \"suppress msd\" is %s\n\n", integer, weight, …
jephthah 1,888 Posting Maven

the logic of your palindrome function was correct, but there were a few errors in your code structure that prevented the function from being executed properly.

. i have commented out the errors and put notes indicating what the error was.

#include <stdio.h>
 #include <string.h>
 #include <ctype.h>

 #define MAX_LEN 50

/* Create external function */
char palindrome (char *string, int len)
{
    //len = strlen(string-1);   <--- NO, do not try to take length of pointer!!
    //                               this is why "len" is passed in as an argument!
   
    
    printf("\nEntering palindrome():\n   str \"%s\", len %d\n", string, len);
 
    if (len <= 1) 
    {
       printf("   remaining length %d, all done \n", len);
       return 1;
    }
    else if (string[0] != string[--len])
    {
       printf("   str[0] \'%c\' != str[%d] \'%c\'\n", string[0], len, string[len]);
       return 0;
    }
    else 
    {
       printf("   str[0] \'%c\' == str[%d] \'%c\'\n", string[0], len, string[len]);
       return palindrome(++string, --len);
    }
}


int main(void)
{
/* Create variable for string */
    char string[MAX_LEN];
    int len;

    // char palindrome (char *string, int len);  <--- NO, do not declare prototypes 
    //                                                inside the main() function !!!


    /* Explain purpose of program to user and prompts for input */
    printf("This program will test a phrase inputted by you to see\n");
    printf("if it is a palindrome.\n\n");
    printf("Please enter a word or phrase of no more than 50 characters.\n\n>");


    /* Receive input from user and stores it in input_string array */
    scanf("%s", string);

    len = strlen(string);   // <-- DO get the length of the string after the input

    /* Call external …
tux4life commented: ++rep for all your effort :) +8
jephthah 1,888 Posting Maven

I haven't learned fflush, fgets, strtol, strcpy yet. These are all new things. Is there a simpler way to do this?

you should learn them. but yeah, yeah, i know....

so use your original scanf input method.

but you definitely need to know 'sprintf' and you need to know 'strcpy'. any simpler than that, gets complicated. i'm not going there. jsut look them up

int integer, valid;
char weight[3];                        // for two digits
char numStr[16], suppress_msd[16];     // oversized
char *ptr;                             // for the strtol() function



///////////////////////////////////////////////////
///////////////////////////////////////////////////
////     HERE IS YOUR ORIGINAL INPUT ROUTINE   ////
////                                           ////

/* Prompt user for input */
printf("Enter integer: ");

/* While there are more integers at input */
while( scanf("%d", &integer) != EOF)
{
	 /* Print a blank line */
	 printf("\n");

	 /* Update loop */
	 printf("Enter integer: ");
}

////     I DO NOT RECOMMEND THIS METHOD        ////
////                                           ////
///////////////////////////////////////////////////
///////////////////////////////////////////////////


/* convert integert to string */
sprintf(numStr,"%d",integer);


/* suppress msd and get weight, whatever this means */
strcpy( weight, numStr[0]);           // the msd, as string
strcpy( suppress_msd, &numStr[1]);  // all the rest, as string


/* you want your weight (apparently) multiplied by 10 */
strcat(weight,'0');


/* it doesnt get any simpler */
printf("\nYour number was %d.\n\"weight\" is %s, \"suppress msd\" is %s\n\n", numVal, weight, suppress_msd);
jephthah 1,888 Posting Maven

Hey, by the way, i just found at least one error in the code that you replied to above. use this fixed version.

int numVal, valid;
char weight[3];                        // for two digits
char numStr[16], suppress_msd[16];     // oversized
char *ptr;                             // for the strtol() function

/* basic input minimal error checking */
do
{
    valid = 0;
    printf("Enter number: ");
    fflush(stdout);
    fgets (numStr, sizeof(numStr), stdin);
    numVal = strtol(numStr, &ptr, 10);

    /* remove trailing newline from string */
    if (numStr[strlen(numStr)-1] == '\n')
    {
        numStr[strlen(numStr)-1] = 0;
        valid = 1;
    }
}
while(numStr == ptr || valid == 0;);
/* continue to get input if strtol didnt convert an int (ptr == string)
or if the valid flag is not set ... */


/* suppress msd and get weight, whatever this means */

strcpy( weight, numStr[0]);           // the msd, as string

strcpy( suppress_msd, &numStr[1]);  // all the rest, as string


/* you want your weight (apparently) multiplied by 10 */

strcat(weight,'0');

printf("\nYour number was %d.\n\"weight\" is %s, \"suppress msd\" is %s\n\n", numVal, weight, suppress_msd);

EDIT: changed results to be strings, not ints.

EDIT 2 : fixed exit condition on the do/while loop

EDIT 3 : added *ptr; declaration

jephthah 1,888 Posting Maven

thank a lot man!
wait, so this goes into driver4.c or in presults.c ?

hell if I know! LOL :)

i don't know if it does exactly what you want to do. modify it for your own purposes.

jephthah 1,888 Posting Maven

If I enter 100 ... I expect for suppress_msd to return 00 and for the weight to be 10.

this is totally off the cuff, and i havent tried to compile it, but this is the basic idea of what you're trying to do. I don't understand why it has to be so complicated.

int numVal, valid;
char weight[3];                         // for two digits
char numStr[16], suppress_msd[16];     // oversized

/* basic input minimal error checking */
do
{
    valid = 0;
    printf("Enter number: ");
    fflush(stdout);
    fgets (numStr, sizeof(numStr), stdin);
    numVal = strtol(numStr, &ptr, 10);

    /* remove trailing newline from string */
    if (numStr[strlen(numStr)-1] == '\n')
    {
        numStr[strlen(numStr)-1] = 0;
        valid = 1;
    }
}
while(numStr == ptr || valid == 0;);
/* continue to get input if strtol didnt convert an int (ptr == string)
or if the valid flag is not set ... */


/* suppress msd and get weight, whatever this means */

strcpy( weight, numStr[0]);           // the msd, as string

strcpy( suppress_msd, &numStr[1]);  // all the rest, as string


/* you want your weight (apparently) multiplied by 10 */

strcat(weight,'0');

printf("\nYour number was %d.\n\"weight\" is %s, \"suppress msd\" is %s\n\n", numVal, weight, suppress_msd);

EDIT: changed results to be strings, not ints.

EDIT 2 : fixed exit condition on the do/while loop


.

jephthah 1,888 Posting Maven

just going on Google searches, these functions appears to be some specialized libraries tfdef.h and chrutils.h peculiar to a professor at the University of Hawaii.

Is your assignment requiring you to use all of these functions?

jephthah 1,888 Posting Maven

I'm sorry, i've got problems here and i can't follow your functions. where did these functions come from?

you've got these libraries tfdef.h and chrutil.h with all these functions all over the place i have no access to. i've never seen them before. i could cipher it out with the full prototypes, but that would be ridiculously time consuming.

If you're forced to use these functions, im afraid im not going to be much help.

otherwise i would want your program requirements and rewrite it in standard C.


EDIT: sorry, but the header doesn't tell me very much. i cant use the header file on it's own, i'd have to have pre-compiled libraries linked in my environment. I don't have any way to compile this.

jephthah 1,888 Posting Maven

actually, sorry, that is just too much code to look at. especially since i dont really understand what you're trying to do. and you've got some funky non-standard libraries going on in there, that i wouldn't be able to compile it even if i wanted to.

can you explain, simply, what exactly youre trying to do? maybe one of us can give you a hint as to how we might do it and then you could compare methods.

i really suspect that your code is about 10-20 times too large for what you need to do.

.

jephthah 1,888 Posting Maven

dude, that's WAY too much code to look at.

but it's nicely formatted and commented. so thanks for that.

i'll try and give it a once over, but in the meantime, you should really learn to use fgets() inconjunction with strtol() to get your input. using scanf() can do it correctly, but it is overly-complicated to make it robust, and prone to input error IMO.

EDIT: okay, this problem obviously has nothing to do with scanf. sorry, it's just the usual suspect
.

jephthah 1,888 Posting Maven

ah, you're so close.

it's true you want to move the left hand "pointer" inward by one character each time. so you correctly do a "++string" as the first recursive argument in line 44.

it's also true that you want to move the right hand pointer inward by one place as well, so you do a "--len" as the second recursive argument.

but the *relative* position of the right hand "pointer" to the left hand pointer is actually decreased by *two* places each time. and since you're not actually using a real pointer there, but it's your "len" variable that determines the relative distance the right pointer is from the left, you need to decrement that length by a total of two.

you can do it a couple ways, by having "len = len - 2" as the second recursive argument, but you will then need to modify teh comparison value in line 40 to account for that. you could leave "--len" in line 44, and add a post-decrement to len in line 40 "len-- <= 1" or line a pre-decrement to len in line 42 "string".

any of those should do it.

(NOTE: if you hadn't been doing so already, you should have put some print statements after each conditional to see exactly what the left pointer is looking at, what the caluclated len value is, and what the right pointer is looking at each time.... it would really help your debugging to …

jephthah 1,888 Posting Maven

okay man, i wrote your palindrome recursive thing, in three lines of code. well, six lines with whitespace. it can be done and it's simple ... once you wrap your head around recursion, which is the hard part.

i'm tempted to give it to you, but I'll be doing you a disservice as you won't learn from that.

so i'll give you the method, laid out in a pseudocodeish example sort of way.

cheers.

in function main()

char* str="annabanna"
int len(str) = 9

call palindrome(char* str, int len);

--->inside palindrome:

         annabanna
         ^       ^
   *str='a'      
   --len=8       str[len]='a'
     ++str
     --len

    call palindrome(str, len);

    --->inside palindrome:

             annabanna
              ^     ^
       *str='n'      
       --len=6       str[len]='n'
         ++str
         --len

        call palindrome(str, len);

        --->inside palindrome:

                 annabanna
                   ^   ^
           *str='n'      
           --len=4       str[len]='n'
             ++str
             --len


            call palindrome(str, len);

            --->inside palindrome:

                     annabanna
                        ^ ^
               *str='a'      
               --len=2        str[len]='a'
                 ++str
                 --len


                call palindrome(str, len);

                --->inside palindrome:

                         annabanna
                             ^
                   *str='b'      
                   --len=0        str[len]='b'
                     ++str
                     --len

                    call palindrome(str, len);
                    
                    --->inside palindrome:

                        len = 0  --> condition len <= 0 is true
                        return 1 --> success, found palindrome


NOTE:  if at any time, the *str character did not match
       the str[len] character, then the condition for 
       inequality would cause a return value of 0, 
       indicating failure, no palindrome found
jephthah 1,888 Posting Maven

The error I get in the compiler is "warning: control reaches end of non-void function in function char palindrome(char *, int).

char palindrome (char string[], int i)
{
    int ans;
    int k = strlen(string);

    if (k <= 1)
        ans = 1;
    else if (string[i] != string [k-1])
        ans = 0;
    else 
        return palindrome(string, i+1);

}

well, that's simple. you don't have a return statement for the first two conditions, only for the third. you need to always return.

i reccommend that you should have one and only one return statement at the end of the function, that will always be reached regardless of the conditional branches. \set the various return values in the conditional branches, but don't return until the end.

also notice how i indented your code. you should always indent your code properly. otherwise you can't hardly read the code and will be prone to making these kinds of errors.


another problem i see, is what is "ans"? you're setting this variable in teh function, but it serves no purpose and is neither returned nor passed back to the caller.


.

jephthah 1,888 Posting Maven

no problem. if you get stuck, come back and post your code. :)

jephthah 1,888 Posting Maven

these functions will be your friends:

fopen()
strstr()
strcpy()
fclose()

look 'em up.

jephthah 1,888 Posting Maven

eeee??????????/////////?///?????//////////////????eee

LOL WUT?

WaltP commented: It's bad enough this post has been resurrected 4 times for nothing, but why do you have to keep it alive for this crap? +0
jephthah 1,888 Posting Maven

one problem is your function, palindrome, expects two integers to be passed into it. you've declared these integers in main as 'i' and 'k' but you don't assign any value to them before passing them into the call to palindrome. therefore, they will either be zero or some large value of random garbage.

also, your function palindrome, which has two ints being passed as inputs, then completely ignores whatever input you might have passed in for the one called 'k' and assigns a value of string length to it.

you probably want to remove 'int k' from the palindrome function prototype, and declare 'int k' as local variable in palindrome.

this still doesn't fix the fact that you are not passing anything in for 'i' what is the purpose of 'i' what should the 'main()' routine be setting it to, before passing it into the palindrome function.

there are other problems. that's just a start. but it will probably lead you to discover and fix them.

you really should be running this in a debugger, to step through each line and check what the variables are being set to.