jephthah 1,888 Posting Maven

look, i'm tellin' ya, dood, everything you're trying to do is in Beej.

if only you'd bother to read it, you'd see for yourself, there's an entire chapter on message queues.

.there's no point in me trying to explain this to you at this point, because i haven't found a single introductory text that explains it better than Beej. i would just essentially be repeating everything he says. since he's already said it, why should i copy him.

just read the chapter already.

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

You know you are old when...

for teh first time in your life your wife wants more sex than you do

:(

jephthah 1,888 Posting Maven

you will not trick me into falling for your bourgeois shenanigans.

jephthah 1,888 Posting Maven

it was thought up by overpaid marketers after thousands of manhours and catering bills.

the end result is just something that can be verb-ifyed, in an attempt to move into google's marketspace. that it rhymes with "ping" is an attempt to associate it with information gathering.

all in all, its not a bad choice. they may gain some traction on google. but i think it will always lag behind in market share. there doesnt seem to be anything fundamentally different, no paradigm shifts. no ground-breaking revolutionary technology.

just more of the same "catch up" game.

conclusion: "meh"

jephthah 1,888 Posting Maven

yeah.... your FACE doesnt matter!

lololololol

jephthah 1,888 Posting Maven

oh my god......
you are making fun of me

no, well I'm not.... actually, i thought this was interesting because we've got a true partisan railing about VOA on this board.

at first i thought he was some kind of idiot zealot, and i was about ready to make fun of him, but then i looked into it a little bit, and he has a point about the history and culture stories being really watered down. but in fairness, they are no worse than US History textbooks used in our high schools.

so, here in the least controversial forum, i find new controversies.

interesting. :)

jephthah 1,888 Posting Maven

build menu settings is now "expert" ?

:-O


.

jephthah 1,888 Posting Maven

rule #1: don't give away homework answers
rule #2: when giving away homework answers, at least use code tags
rule #3: see rule #1

jephthah 1,888 Posting Maven

i swear, this guy.

i should probably be more tolerant, but his umpteen threads repeating the same problem, with the same variation on URGENT PLS HELP NOW headlines, along with his imperiously demanding tone.

it's just making it really difficult to care.

.

Salem commented: Indeed +20
jephthah 1,888 Posting Maven

i mean really, think about it..

it doesn't even matter.

does it?

jephthah 1,888 Posting Maven

to try and clarify, by adding the value of 'A' (0x41) to any byte that has a value less than the space ' ' (0x20) character, and printing the resulting char appended to a caret '^', the ascii values will be printed like so

value    disp
-----    ----
0x00      ^A
0x01      ^B
0x02      ^C
...
...
0x1E      ^_
0x1F      ^`

as to posting code with indentations, you have your editor of choice treating TAB's as tab characters ('\t'). which is probably the default behavior. especially when you mix that up with spaces for indenting, you get a result that looks clean in your editor, but is wildly variable results in most other editors.

and part of the problem is with this site, because it treats all TABS as 8 spaces wide. many editors make tabs 4 or 5 spaces wide. so even if you only use TABs consistently, it still will look ugly here, because it gets so spread out, and will wrap across the screen

the trick is to change your editor settings so that all TAB characters are converted to a certain number of spaces. there should be an option for this under preferences or settings. set it anywhere from 3-8 spaces. I prefer 4. by forcing tabs to spaces (whatever amount) it will cause your code to always look consistent and clean no matter what editor opens it, or where you copy-and-paste it.

this forced conversion of TABs to spaces is actually required …

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

well, i've got the same problem walt has: i don't know what your question is.

can you try to formulate a specific question, about something that's not working for you? what are you doing, what do you expect to happen, and what is actually happening? i'm not going to guess. if you pose some specific issues, i can look for obvious problems, and if needed, then tomorrow evening i can try and run it on my linux box.

we'll help you out but you need some patience. the delay in help will also encourage you to poke around at it yourself in the meantime. personally, i find that's the best way to learn :)


P.S. have you looked at Beej's Guide yet? i've found that almost every question about using C language to set up network hosts and clients can be answered there.

jephthah 1,888 Posting Maven

well, this is some kind of voodoo guru stuff. pretty clever use of shifts and AND'ing to perform a modulus.

But i think i'm seeing the basics: this is the LCG as it is implemented by Apple's Carbon C-language API, according to the wiki link i posted above

given the LCG equation, X[n+1] = (a*X[n] + c) mod m ,

the Carbon LCG implements it with a = 16807, c = 0 (a special case), and m = 2^31 - 1. The choice of these numbers involve modular arithmetic discussions on Mersenne Primes and primitive roots modulo, and i have to admit at that point it gets beyond me pretty quickly.

but notice that in your program, as it stands, your 'tempseed' value = 33614 * 1, and then this is then shifted right 1 bit, which is the same as dividing by 2 ... so now you have 16807 (the 'q' variable in the program).

this next part is a little confusing:

to teh above 'q' value it adds the 'p' value, which is the upper 32 bits from the previous 64-bit seed. this initially is less than 32 bits, so that added value = 0, but as this iterative process develops, the seed varies across most of the range of a 64-bit value so the corresponding upper 32 bits (the 'p' variable) is a meaningful value.

now this part follows the explanation you received:

this summed value has its modulo …

jonsca commented: Nice attept to elucidate it -- I couldn't begin to tell you if it's correct +4
jephthah 1,888 Posting Maven

interesting question.

i believe this is a proper LCG. At least i can't say that it isn't. I don't fully understand how, but it looks like he's using shifts to perform modulus operation. see here.

im interested to know the details if you find out.

jephthah 1,888 Posting Maven

hi tom. nice intro. welcome :)

jephthah 1,888 Posting Maven

this is probably the most interesting Community introductions thread i've seen yet.

jephthah 1,888 Posting Maven

Now that's just wishful thinking ;)

hey, it's not about me.

we always dream of a better place for our children.


.

jephthah 1,888 Posting Maven

okay fair enough. i had a mistaken impression of your opening sentence, after becoming overwhelmed by the sheer magnitude of your copy-and-paste.

if you post an answerable question, i'll do my best to answer it.


.

jephthah 1,888 Posting Maven

ive never learnt about sprintf before

well, now's your chance to learn another basic fundamental function in the C library, isn't it? It's tremendously easier to use and more widely applicable than that "strtok()" function you were abusing.


besides my lecture told me this should be really easy less than 10 lines.

yeah, that sounds about right. the pseudo-code i posted is overly verbose, only to explain what is going on; it doesn't not make a 1:1 mapping of lines of actual code.


and i think i will just use my first function prototype to define the hashfunction,,will u give me a hint how to work on this function protytpe:

int hashfunc(unsigned int ID)

hey man, you can do whatever the hell you want, but there's no way you're going fit the full range of a 10-digit number into an unsigned int. well over half of the possible values will cause an overflow.

so, what part of this don't you understand?

should i realy use array for this?

no, you should not.

i've already given you a solution. now you can do it the way i've suggested, or you can come up with your own. in any event, you need to start coding.


.

jephthah 1,888 Posting Maven

wait wait, let me get this right.

you just posted your homework program requirements and dumped a shitton of code, and said "Urgent" and "Please help me finish this"

yeah.... I don't think so.

see, the way it works around here is you need to formulate a specific question about a specific problem that you're having.

I don't know wehre you got this code, if you wrote it, or a classmate, or if it was provided as a shell by your instructor, or a combination of those... but you really need to get a handle on what you're doing, back up, and start approaching this one functional requirement at a time.

come back when you have a coherent question, and you can get an answer.

jephthah 1,888 Posting Maven

That being said, we are launching a new design for the site in about a month. I will give it a try at first, not using a modal, and see if all of the activity stats drop off.

and this is the new design where posts are automatically closed after 3 months of inactivity.

right?

:)

Nick Evan commented: Haha +0
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

As to the original 'problem', would goto be accepted?

hahahah

LOL

jephthah 1,888 Posting Maven

yeah, i just can't see how this is an issue. if you don't want to join, then use one mouseclick to get the window off and continue browsing. if this bugs you so much you won't continue to use the site as a free reference.... well, don't let the door hit you in the ass on the way out, okay?

there are far more annoying things out there like advert popups and flashing banners saying "You're the 1,000,000th Visitor!"


anyhow, Stevishere, welcome to Daniweb. Glad you joined! :)

.

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.

jephthah 1,888 Posting Maven

use "strcpy()" ... note the lack of n.

so rather than specififying the number of bytes, n, as with strncpy(), it will just take the entire string from the starting pointer.

strcpy(&payload,&buff[23])

remember a "string" is defined by the presence of a terminating NULL character; your char data 'buff' must have a NULL at the end. most string functions (like strcpy() and sprintf()) put a NULL character at the end so this would only be a problem if you handcraft a character array and forget to terminate it with a NULL.


.

jephthah 1,888 Posting Maven

the problem is you've got that "return" statement right near the end of the "else if (i==4)" block.

if you've returned from the function, neither "bzero" nor "fclose" will be called.

this is the danger of putting returns in odd places. unless you have a real reason not to, like device drivers, have one single return call at the END of the function, not somewhere up in the middle.


.

jephthah 1,888 Posting Maven

yeah, i hear ya, but youre gonna have to pony up some of your own code first.

since you're not there yet, you might want to take a look at Beej's Guide ... it is a great reference, full of valuable and relevant examples.

jephthah 1,888 Posting Maven

be advised, if this is a real university course, and you've been told about fgets() you will probably lose points for using scanf() in this manner. it's very fragile as you have seen.

but i understand the full load and looming exams.

sometimes you just have to cut your losses ;P

jephthah 1,888 Posting Maven

It was just some pseudo code to get him started on some idea's.

Must have been a fair idea, because your code uses them. ;)

Sure, its one idea among many.

Personally, I wouldn't have done it that way, i would have used fgetc() to check each element, avoid whitespace, and parse on the newlines. Then i could have avoided the whole disclaimer about the file read method being extremely fragile and breaking if you looked at it cross-eyed. But whatever.

Yeah, i just stuck to just fixing your mess, so he could see why it was broken. it has value as a fundamental lesson of what not to do.


.

jephthah 1,888 Posting Maven

it is now feeding me garbage for the second operation and it is returning the sum of 25
i enter (5 * 5) + (6 / 6) into the prompt every time and i get :
(5 * 5) + (2 / 21)=25

Ahhh, what am doing wrong.

you're using integer types and expecting floating point results.

jephthah 1,888 Posting Maven

but i'm sure you want this thing to "work" and not worry about "long answers" :)

so here is something that works. but just barely. remove your two scanf lines and replace wiht this one:

scanf("%c%d %c %d%c %c %c%d %c %d%c",&a,&myVarA,&b,&myVarB,&c,&d,&e,&myVarC,&f,&myVarD,&g);

the reason why this will work, is that it follows your expected/anticipated whitespace verbatim.

the reason why scanf() generally sucks for getting input from a terminal, is that it follows your expected/anticipated whitespace verbatim.

tehre is a way to make scanf() robust, but it's quite complicated and i barely know how to do it much less explain it. the reason why i dont care, is becasue i always use fgets() or fgetc() for getting input from a terminal.


However the chunk of code Adak posted is working as I add more Arithmetic opperations to it.

oh i didnt see adaks code. which is just a generalized version of the longer specific code i posted.

and yes, it is "working" ... but i repeat, it is working just barely.

this code will fail, and teh program may crash spectacularly, as soon as your user mistypes an extra bit of whitespace to the terminal.

i don't consider that to be "working". but if your course instructor refuses to teach you fgets() and other IO functions until later, i guess it will do for now.


.

jephthah 1,888 Posting Maven

well, unfortunately, the quick answer is "scanf is a terrible method to get terminal input"

the long answer is that scanf can do it properly, but in a very complex manner.

a longer answer is that fgets() or fgetc() can do it properly but in a not-quite-so-complex manner.


.

jephthah 1,888 Posting Maven

adak

if youre gonna post pseudo code, then dont structure it as C, and box it as C-syntax text. that just confuses the hell out of some new people.

also, why would you increment 'k' when you have the same variable indexed as columns in the for loop?

finally, your use of fgets is broken, as it won't read a 10 character line like you think it will.

so now that you've made a big mess, let's just give this piece to him so it makes some sense.


mariosbikos

here you go, mate. start with this.

#include <stdlib.h>
#include <stdio.h>

#define MAX_ROWS       10
#define MAX_COLS       10

int main(void)
{
    FILE *fileptr;

    char map[MAX_ROWS][MAX_COLS];
    char fileRow[MAX_COLS + 2];          // account for newline and NULL

    int row, col;

    if ((fileptr = fopen("battleship.txt", "r")) == NULL)
    {
        perror("File Open Error");
        return -1;
    }

    for (row = 0; row < MAX_ROWS; row++)
    {
        fgets(fileRow, sizeof(fileRow), fileptr);

        for (col = 0; col < MAX_COLS; col++)
            map[row][col] = fileRow[col];
    }

    fclose(fileptr);

    // now you have the map loaded, 
    // so do the rest of your program

    return 0;

}

NOTE: this requires that your "battleship.txt" file (or whatever you want to call it) is precisely the size of your intended map, that each line has one and only one newline after each row of characters, and that there is absolutely no additional whitespace anywhere in the file.

variation from this will cause the program to fail …

jephthah 1,888 Posting Maven

please repost your most current code. please use code tags and indentation.

thanks.

jephthah 1,888 Posting Maven

y u cant show ur effort a little here plz?????

how about YOU show a little effort, and keep your mess in one thread.

jephthah 1,888 Posting Maven

okay, look at your hashfunc. i've added indentations, for readability. you should always do the same thing.

int hashfunc(unsigned int ID)
{
    int a,b,c;
    float j,k;
    int e=0;

    j=ID/1000;

    a=strtok(j,".");
    b=strtok(j,"\n");

    c=a+b;
    k=c/1000;
  
    e=strtok(k,"\n");

    return e;
}

now this function, it's quite a mess. you have an integer for an ID. you try to assign it to a floating point value by dividing it by 1000. j=ID/1000; but this doesnt work

doesnt work because ID/1000 is an integer divided by an integer, which gives an integer. that resulting integer will then be put into the float variable 'j' but you will have lost the 3 bottom digits. example ID = 123456 .... ID/1000 = 123 .... j = 123.000 . if you really need to do this, then you would do it like so: j=ID/1000.0; , using 1000.0 forces the program to treat the result as a floating point value so example ID = 123456 .... ID/1000.0 = 123.456 .... j = 123.456 .

another problem, looking at your requirements below, is that you have a 10-digit integer as a key. an unsigned int is typically 32 bits, for a maximum value of 4 billion and change. a 10 digit value can be over 9 billion. exceeding the range causes an overflow error.

then you're trying to tokenize a floating point value? well, that's just wrong. strtok is for strings. not values.

it's pointless to carry on. this code is pretty much unrecoverable. you …