jephthah 1,888 Posting Maven

i don't know why it doesnt compile for you.

let me ask you something: what compiler are you using?


.

jephthah 1,888 Posting Maven

i wish you'd use as your opening tag... the syntax coloring makes it readable, and the line numbers help debug discussions.

you still have about 20mins to edit :P[code=c] as your opening tag... the syntax coloring makes it readable, and the line numbers help debug discussions.

you still have about 20mins to edit :P

jephthah 1,888 Posting Maven

blast from the past!

has it only been a year? it seems a lot longer....

jephthah 1,888 Posting Maven

C++ allows different definitions of pow() based on the type of argument. your problem appears to be that you're calling them with integer arguments which is ambiguous as it allows the pow() to fit more than one version.

try casting the args as doubles: pow(2.0, (double)bBita - 1 - i); .

jephthah 1,888 Posting Maven

not sure why the trailing NULLs are a problem. they probably existed in the memory before program startup, or were initialized in some manner during execution.

the first NULL after "2:00 pm" signals the end of the string. why do you care that there are more than one? anything after the first terminating NULL is not considered to be "extra data"

or am i missing something?


.

jephthah 1,888 Posting Maven

wish you'd use tag for syntax highlighting. much easier to read.[code=c] tag for syntax highlighting. much easier to read.

jephthah 1,888 Posting Maven

i dont know wtf is up with that place. it looks horrible. combined with the blatant bot-plagiarism or whatever, i think someone ought to take it out.

surely we have some folks skilled in the arts of the black hats? the site is such a crappy design, im sure the security is lousy, too.

jephthah 1,888 Posting Maven

wait, what?

its been three days ... why haven't you guys finished helping this kid write his spyware program, yet?

who do i give neg rep to?

Salem commented: Anyone you like, I keep running up my daily limit, but it does no good. Reporting the thread didn't work either. Suckssssssss +29
jephthah 1,888 Posting Maven

i get no love :(

William Hemsworth commented: Awwh *hug* +8
jephthah 1,888 Posting Maven

he posted 3400 posts in one day.

yeah, their membership is obviously composed of bots.

jephthah 1,888 Posting Maven

well, then maybe one of you Win32 API gurus can post something remotely resembling an answer to the OP's question??

jephthah 1,888 Posting Maven

^ the question was answered and the OP marked it as "solved" already.

so why do you think its necessary to come in and add your wrong answer?

jephthah 1,888 Posting Maven

in general, the best way to read data from text files is to use "fgets()" which reads one entire line at a time, or the number of characters specified if a new line is not found within that number of characters.

then you can do whatever you need to with each line. fgets will return a NULL pointer when there is nothing left to read (the end of file), so its perfect for use in a while loop .

become familiar with how the function works, you will likely use it a lot

http://www.cplusplus.com/reference/clibrary/cstdio/fgets/

jephthah 1,888 Posting Maven

W00T!!!!1

i got my star!!!!

now i can finally go to bed.

:P

jephthah 1,888 Posting Maven

okay, actually the problem is not due to that 'break' statement. the root of your problem is that you want to use fgets() not feof to control your read loop. but then that changes how you handle copying the string read from file1 to file2

then theres a number of ways you can deal with copying it. an intermediary buffer, plus something like strncpy() and strcat(), or just using pointers, which i prefer.

ok, it's late, and you've been a good sport. so here's what i would do. be advised, it has essentially no fault-tolerance. but that fits with the rest of the code, so at least it won't stick out in that regard.

just make sure you take time to really understand whats going on.

while(fgets(line,20,fp1))
    {
        char *buf_p = buf;  // pointer to string 'buf'
        char *line_p = line;  // pointer to string 'line' read from file1
        int index = 0;  // index counts position for '-' inserts

        while(++index <= 19 && *line_p != '$' && *line_p != '\n')
        {
            if (index % 5 == 0) // '-' inserted at pos. 5, 10, 15
                *buf_p++ = '-';

            else
                *buf_p++ = *line_p++;  // otherwise copy each char
        }

        *buf_p++ = '\n';  // when done, append newline and NULL
        *buf_p = '\0';

        fprintf(fp2,buf);  // then print the entire buffer to file2

    }

.

jephthah 1,888 Posting Maven

hello and welcome.

look forward to seeing you on the forums!

jephthah 1,888 Posting Maven

welcome! and greetings from rainy seattle!

i too remember old school slackware. Church of the Subgenius. Give me Slack. :) I use Ubuntu on my laptop, Fedora on my desktop.

(right now im on my wife's Vista laptop, but please dont tell anyone i dont want to lose my street cred! :P )

jephthah 1,888 Posting Maven

WELOME Tony.

feel free to ask questions in any forum related to your studies. I went back to college as an older student, myself, so i know the additional challenges you face.

glad you're taking the initiative to retrain yourself.

we're here to help

jephthah 1,888 Posting Maven

sounds great. i think several forums will welcome your expertise.

FWIW, i almost got stampeded by some Buffalo in yellowstone park.

i also dig Buffalo wings.

:P

jephthah 1,888 Posting Maven

welcome! hope you find what you're seeking.

jephthah 1,888 Posting Maven

welcome. the java forum awaits your enthusiasm :)

jephthah 1,888 Posting Maven

welcome! please join our web development forums and contribute to the discussions or ask questions as you like.

jephthah 1,888 Posting Maven

your in the right place then.

'cause we're full of it.

:P

jephthah 1,888 Posting Maven

hi tom, and welcome

hope you stick around. python and java are very popular, and we're always in need of people to contribute to the discussions.

jephthah 1,888 Posting Maven

hi, elie, glad youre here. hope you stick around and join the discussions.

jephthah 1,888 Posting Maven

wow! sounds cool. I think you scared everyone away!

no seriously, welcome and I hope you stick around. sounds like you've got a lot of insight that could be quite helpful to people with tech and programming questions. and, who knows, maybe someone here might be able to help you.

glad you're here, thanks for posting.

.

jephthah 1,888 Posting Maven

hi. welcome to daniweb. thanks for posting.

please direct specific questions to the appropriate forum.

jephthah 1,888 Posting Maven

hello.

generally this is just a hey whassup shout out to the new folks.

specific questions would be more likely to get a response, if posted in the forums.

but welcome. stick around and contribute your questions or answers, whichever you have more of! :)

jephthah 1,888 Posting Maven

things to talk about.

but that doesnt stop me.

jephthah 1,888 Posting Maven

well, howdy backatcha, Tex.

i remember using a Tandy when i was a kid. TRS-80. It hooked up to a TV.

i dont remember the "sensation", though.

welcome to daniweb. i see you've gotten started already! :)

jephthah 1,888 Posting Maven

awsome programming skills are a long time coming, and probably not so easily to those who hate code! :P

welcome, and good luck in your studies. lots of people here are willing to teach anyone who is willing to learn.

jephthah 1,888 Posting Maven

welcome and good luck to you. dont think i can help you much with 3G mobile, but maybe you can teach me something.

jephthah 1,888 Posting Maven

thanks for the SPAM, but i think I'll pass. potted meat products give me gas.

jephthah 1,888 Posting Maven

'ello, mate, and welcome!

jephthah 1,888 Posting Maven

the problem is this:

fscanf(fp1,"%c",&ch2);
            if(ch2=='$'||ch2=='\n')
            {
                break;
            }

as soon as you find either a $ or a \n, you break out of the while() loop, ending your entire search.

fix that and you'll be done.

im not going to critique your code for "best practices"

jephthah 1,888 Posting Maven

const means the program can not modify the value volatile means the value may be arbitrarily modified outside the program.

the two are separate and not mutually exclusive.

use them together, for instance, in the case of reading a hardware status register. const prevents the value from being stomped on, while volatile tells the compiler that this value can be changed at any time external to the program.

this const volatile <type> <variablename> will thus satisfy both requirements and prevent an optimizing compiler from incorrectly optimizing the code, that it would do if only "const" were used.

Dave Sinkula commented: I sometimes like to add something like, "interpret 'const' as 'read-only'." But you've got all bases covered here already. +18
jephthah 1,888 Posting Maven

great. good job. now you know.

so.... what was your question? i mean, beside "it doesnt work" ?

jephthah 1,888 Posting Maven

"no need to worry", as long as 'value' contains a value that is less than 65536, otherwise the hex string is going to be 5 or more characters in length before the NULL is considered,

at which point the behavior is undefined, and will most certainly be bad.

also the for loop that initializes checkSum is unnecessary and serves only to indicate the programmer has a lack of understanding of sprintf()

jephthah 1,888 Posting Maven

generally speaking:

int  * myPointer;
int myValue;

...

myValue = *myPointer;

myValue now contains a copy of the value that is at the location currently pointed to by the pointer, myPointer.

is this what you're asking?

.

jephthah 1,888 Posting Maven

the string pointed to by checkSum will contain the numerical value of Total is expressed as a hexadecimal string due to the 'X' specifier. specifically, any letters (A-F) will be uppercase letters rather than lowercase due to the fact that the 'X' specifier is uppercase

furthermore the string will be at least four characters in width, and will be zero-padded if the resulting hex representation is less than four characters. this is due to the '04' in the format specifier.

in this specific example, the string of chars pointed to by checkSum will be 007B and terminated by a NULL character \0 the memory location starting at the address of checkSum will be 0x30 0x30 0x37 0x42 0x00 .

jephthah 1,888 Posting Maven

yeah, now you need to put your indentations back in there.

if you put the code tags in the first time around, your original indentations that you've cut and pasted will persist.

forgetting to code tag it, then editing later, will cause your original indentations to disappear.

you can edit the post, cut out all that code, then repaste your original code with the indentations back in, betwen the code tags.

.

jephthah 1,888 Posting Maven

how to use [code] tags?

specifically, how do i type the opening and closing code tags in my post, as an example, without causing the code tags to activate?

like this:


HEY NOOB! USE CODE TAGS, AIGHT???

<code=c>
int main(void)
{
// your noob code here
return 0;
}
</code>

with [ square ] instead of < angle > brackets of course.

jephthah 1,888 Posting Maven

you need to use opening AND closing tags

this includes an opening tag (the code=c , like you did)

but also needs a CLOSING TAG

at the end.

you understand the concept of markup tags? its like HTML tags but with square brackets rather than angle brackets.

jephthah 1,888 Posting Maven

what errors? from what code? what have you done to try and fix it?

jephthah 1,888 Posting Maven

no, its not.

use the edit button and surround your code with

[code]

tags

jephthah 1,888 Posting Maven

It may be possible that profesor has given the OP to design a 'home made' string class which should have a member called swap(), then it makes sense and OP is actually on the right track.

and that underscores my point that you and i have no context to tell some student that his professor is full of beans.

putting those ideas in some beginning students head will only serve to get them embarrassed, or worse.

jephthah 1,888 Posting Maven

i'ma get that star if'n it kills meh.

jephthah 1,888 Posting Maven

im still feeling bad about attacking poor Trav based on such slim circumstantial evidence. :(

its obvious now that he was just being helpful here.

jephthah 1,888 Posting Maven

you should always use code tags:

and make sure your tabs/indentations come out right. go fix it now. you've got 15 mins left to edit.

once you format it so that it's readable, then i'll take a look.[code=c]

and make sure your tabs/indentations come out right. go fix it now. you've got 15 mins left to edit.

once you format it so that it's readable, then i'll take a look.

jephthah 1,888 Posting Maven

The "Test" of you professor is perhaps not good. ... What sky diploma told you must be true..

i dont know, you may be right.... BUT

it's generally a Bad Idea for a first year programming student to tell the professor the fundamental premise of his assignment is flawed.

unless that student is prepared to deliver a bulletproof example and orally defend it against close scrutiny.

at this level, given the OP is still asking basics, its probably best to fit the answer to the question, regardless of whether the question is technically precise.


.