the format specifier for a long long int is
long long myBigNum=600851475143;
printf("the number is: %lld\n",myBigNum);
.
the format specifier for a long long int is
long long myBigNum=600851475143;
printf("the number is: %lld\n",myBigNum);
.
at the "bit level", every integer is inherently binary and hex and decimal... it does not matter, because there's only a difference when you print it.
so, you can make it hard if you like, just for the sake of having a challenge or if your instructor requires you to do so for learning purposes.
but if you're not required to make it difficult, i'd say use the <stdlib.h> standard library functions whenever possible.
why so complicated? all you really need is "strtol()" and the addition operator.
int binaryAdd(char *first, char *second, int *sum)
{
int val1, val2;
char *ptr1, *ptr2;
size_t length;
val1 = strtol(first,&ptr1,2);
val2 = strtol(second,&ptr2,2);
if (ptr1 == first || ptr2 == second)
{
printf("\ninvalid entry.\n\n");
return 0;
}
length = ptr1-first;
if ((ptr2-second) > length)
length = ptr2-second;
*sum = val1+val2;
printf("\n %*s (%d)\n+ %*s (%d)\n\n= %*s (%d)\n\n",
length, first, val1, length, second, val2, length, " ", *sum);
return 1;
}
(The rest is just decoration)
I'll leave conversion of the numeric sum, back into a binary string, as an exercise to the reader :P
.
a "long long" data type is a 64 bit number, and gives
Signed min: -9223372036854775808
Signed max: 9223372036854775807
Unsigned max: 18446744073709551615
.
The GNU MP Big Number Library (gmplib) is an industry standard solution for large number cryptography.
are you trying to get help?
then you should start a new thread, and remember to ask a specific question if you hope to get a specific answer.
I do find it strange that the newspapers in UK keep referring to her as a virgin :) Do they think she's the Virgin Mary or something?
how creepy
i meant int answer = num/.01;
same thing as multiplying by 100,
but i guess u have to use << so im wrong again
that's not the only reason why you're wrong.
mainly you're wrong because you can't divide an int by a float and expect to get a correct integer result.
go on try it. you might actually learn something.
.
no, you need to give US code... as in, the code you're trying to use, so we can see why it's not working.
but since you say it's transmitting properly, the first thing I would do is verify the hardware is connected correctly and is working as it should. put an o'scope or serial analyzer on the RX pin to make certain you're actually receiving anything before indicting the program.
er.. i mean "distributive property"
thanks Dave :$
I will pray for you.
hey pray for me too.
i got a whole list of stuff i'd like to get by June.
thanks
use the additive property:
(a * m) + (a * n) = a * (m + n)
example:
result = (a << 2) + (a << 4);
// result now contains the sum, 4a + 16a = 20a
cout << a << " times 20 = " << result << endl;
.
Your code. Iss verah nice.
[/Borat]
I am confused. First you say you want to write the program. Then you say you want somebody to send the code for such a program to you.
those were two different people.
but as to that second guy, welcome to Daniweb. it's pretty much the reason why the long-term users here are often cynical and jaded towards noobs.
Damn.
Yes he said we have to use Miracle C.
That is what he is going to use to check it.
We have to send him the *.c file and the *.exe file for him to check both.
Salem is absolutely right: you need to drop this class, and demand your money back. this class is a joke and your "teacher" is a damn fool.
you'll do better to study any number of free tutorials you can find online.
In fact, tell your "teacher" to come on here and explain why he thinks using Miracle C is a good idea.
.
post your Q&A sheet right here.
i expect you'll get a few responses from which you can pick and choose which one to use.
Or do you know the 'ultimate' way?
i know the ultimate way
#include<jephthah.h>
newStr_ptr = removeSpacesAndCondense(myString);
it's non-standard and not very portable, but hey, it works on my machine.
main()
what the hell is that?
main must be an int, and it must take an argument
int main(void)
other than that, i dont understand what your question is. i'm still not sure if you even asked a question.
let me take a guess... is your question: "why doesn't this code work with Miracle C ?"
is that it?
what they ^, ^^ said above.
but just to add some background information to put it in context for you:
the 's' in "srand" the stands for "seed"... meaning you have to first "seed" the randomization function before you can start generating random numbers.
this has to do with the fact that nothing is truly random, and these so-called random numbers are actually pseudo-random, generated by a mathematical algorithm that gives the appearance of being random.
the algorithm requires a "seed" value to start, and "srand" is the function that generates this pseudo-random seed.
.
there's a lot of evidence supporting "near death experiences"... that sort of parallels the concept of ghosts.
i dont believe in anything supernatural, personally, but i also don't presume to have definitive answers for things that can't be demonstrated or explained. some people truly believe they have had experiences that i can't account for.
basically it comes down to this: you can talk about your personal experiences and beliefs, but people who go around making declarative statements about the existence or non-existence of things that cant be demonstrated one way or another are full of shit.
in my humble opinion. :)
.
so are you saying that, now that you've finally seen the movie, you realize how much ass it kicks?
:P
dont be offended. just post your code and your question.
I'm super proud
Woo!
w00t!
attaboy.
If you will give me permission, I will send my pseudocode to you in a private message. This will prevent cheating from other students.
We're not your personal tutor. We help everyone here equally, as long as they appear to be honestly trying and not just bums looking for handouts and cheats.
Trust me, your code is nothing special. the fact that you're looking for help on basic concepts means anyone who is going to go to Daniweb to "steal your ideas", is in worse shape than you are.
so post your relevant code and ask specific questions that can be answered. Or don't. It makes no difference to us.
I need real code if you have such ?
as opposed to the fake code we've been handing out so far?
look, how about you just give me your instructor's email address. then i'll create the program, document the source code, validate the executables, and zip everything up into a single tarball and send it to them directly, with instructions for them to give you full credit.
sound like a plan?
.
yeah, seriously. if you're gonna troll, at least be clever.
this racist/linguistic spoof is beyond tired out and overplayed.
i have difficulties understanding your question.
So can sprintf be used to copy the array contents to a integer variable? Or is there any other function i can use to accomplish this?
i prefer to use "strtol()" to allow error checking that doesnt confuse failed conversion with a valid zero (0) conversion.
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main (void)
{
char myString[32];
char *remStr = myString;
long value;
while(1)
{
printf("\n\nenter an integer string: ");
fflush(stdout);
fgets(myString,sizeof(myString),stdin);
myString[strcspn(myString,"\n")]='\0';
errno=0;
value = strtol(myString,&remStr,0);
if (errno)
perror("Error, integer conversion");
else if (strncmp(myString,"Q",1)==0 ||
strncmp(myString,"q",1)==0 )
{
printf("quit requested.\n");
break;
}
else if (remStr == myString)
printf("Invalid, no conversion\n");
else
{
printf(" integer value = %ld\n",value);
if (*remStr != '\0')
printf(" string remainder: \'%s\'\n",remStr);
}
}
return 0;
}
Does anyone made such thing .
I must make it for may classwork but I would rather copy someone else's solution and turn that in as my own work. I believe my instructors are too stupid to recognize plagiarism, so please just send me your codes
pathetic
if this is a life-threatening emergency, you need to get off the computer and dial 9-1-1, or your local police or rescue department.
.
well, good point. even though we are in the C-forum, and my answer is correct for C language... one of his other questions did use C++ syntax.
so there could be some confusion. for C++ i don't think there's a single correct answer, is there?
^^ no, that won't work either because you're expecting the original #defines to remain constant... any modification and recompilation of the GUI will generate a new header file.
^ damned if I know. this is a "feature" of National Instrument's LabWindows/CVI environment. It's basically ANSI C with some extra libraries and a GUI creation tool that auto generates a gui header file based on the gui you created.
its kind of a dumb feature really. it doesnt create any other headers for you, so i dont see really where the benefit is other than perhaps savign time tracking down bugs due to typos.
oh, well. now i've got a 150-case long switch statement. its ugly. and probably slow. but f- it, it works, i guess
:ugh:
i've lost track of your original question, if i ever understood it to begin with.
post your client and your server program files and tell us what's not working the way you expect it to.
so im working in an environment (National Instruments) that auto-generates header files for the GUI.
in my GUI, i have 150-some odd LEDs arranged in a matrix to represent a large relay bank. my LEDs are named and sequenced numerically like
PANEL_LED_1
PANEL_LED_2
...
PANEL_LED_150
etc...
which would allow me to easily control the relays in various configurations if i had a one-to-one mapping of the name with the corresponding value
HOWEVER
the freaking environment auto generates all GUI header files, with virtually no rhyme or reason to the sequences, so i wind up with something like this:
#define PANELRAC_LED_141 2
#define PANELRAC_LED_142 3
#define PANELRAC_LED_143 4
#define PANELRAC_LED_144 5
#define PANELRAC_LED_137 6
#define PANELRAC_LED_138 7
#define PANELRAC_LED_139 8
#define PANELRAC_LED_140 9
and don't think you see a pattern here, because it gets mixed up later, and any time a change is made to the GUI and recompiled a brand new GUI header file is generated and the entire sequence can be re-arranged.
so my question is how best can i associate the string of the #define'd name with the corresponding numeric value.
obviously i would like LED_140 to equal 140. but i can't force that to happen, because i can't modify the header without potentially breaking it in the future.
so i've done this,
case PANELRAC_LED_1:
return 1;
case PANELRAC_LED_2:
return 2;
case PANELRAC_LED_3:
return 3;
...
...
case PANELRAC_LED_124:
return 124;
case PANELRAC_LED_125:
return 125;
case PANELRAC_LED_126:
return 126; …
^ the second one (emp_change) is incorrect.
consider the three basic parameters for a function: inputs are passed to the function. outputs are passed back from the function. return values are assigned by the function.
to get an output, you want the "called" function to modify an element held by the "calling" function. to do this, you generally must "pass-by-reference"
see this site for a good intro on passing by reference.
okay. point taken.
but i said "suspect" not "conclusion"
and im still waiting for code.
for one thing, you dont "free" a pointer. you free previously allocated memory space.
that you're talking about freeing a pointer, makes me suspect you didn't allocate the memory in the first place.
of course it's all speculation at this point, since you haven't posted any code for us to look at.
rapidshare is probably the worst possible place to "host" a document.
post your questions here, and we'll look at it.
your post isnt really nonsense.
at least, it fits the question.
We are not here to argue...
We are here, as a member, to help those who have
problems...
speak for yourself.
i'm here for the smackdown.
just because i have no comment on this matter, shouldn't stop me from commenting.
Hey, scru
I didn't realize you were the Net Nanny around here :icon_rolleyes:
but you shouldn't be mad at me for quoting a Buddhist Zen Master on the subject of Buddhism. Anyhow... everything i've posted is true. or, at least, nothing i've posted is false.
what's this non-standard conio.h and clrscr() crap?
why do you refuse to use code tags?
i dont know if your program works in any meaningful way, because it won't even compile
get this weak stuff out of here.
who cares what it is.
he didnt post any code, and we don't do people's homework.
its not even fun any more, is it.