jephthah 1,888 Posting Maven

^ so.... whatever happened to June 6th?

jephthah 1,888 Posting Maven

rabbi ... what? :-O

jephthah 1,888 Posting Maven

quick note:

you've already declared 'A' as type double * ... so don't declare the type a second time when you allocate the memory

otherwise you're passing the pointer as declared correctly, but you may want to reconsider how you define the array to begin with.

jephthah 1,888 Posting Maven

^^ thanks, A.D. apparently i need to revisit memory allocation..

jephthah 1,888 Posting Maven

the memory at the address pointed to by 'p' has been assigned the values shown. therefore, you can print the null terminated string as you might expect.

but the memory has not been allocated, so if you try to modify it the resulting behaviour is undefined.

at least that's how i understand it. someone else can clarify if i'm missing something.


.

jephthah 1,888 Posting Maven

i'd like to request that we delete all of my posts in this thread, and all posts referring to any of my posts in this thread.

in fact, lets just delete all posts except for the original post, and start over.

i dont have an excuse. i just want a mulligan.

jephthah 1,888 Posting Maven

That's the point. ;)

aaah... ooops. dammit, i'm a mess.

i mean to use &... jeez. i almost, but not quite, had it right the first time on page 1 when i said &= . holy crap, this is embarrassing. i need to pay attention. i really do know better :$

this is what i meant:

#include <stdio.h>

void showcolor(int color)
{
   if ( color &  1 ) puts("violet");
   if ( color &  2 ) puts("indigo");
   if ( color &  4 ) puts("blue");
   if ( color &  8 ) puts("green");
   if ( color & 16 ) puts("yellow");
   if ( color & 32 ) puts("orange");
   if ( color & 64 ) puts("red");
}

int main()
{
   puts("showcolor(0)");
   showcolor(0);
   puts("showcolor(1)");
   showcolor(1);
   return 0;
}

.

jephthah 1,888 Posting Maven

exactly. because what's the point of having 7 bits of color if you only have seven discrete colors. it seems obvious to me that the bit pattern intends to allow mixing.

e.g.:

showcolor(12)
"bluegreen"

.

jephthah 1,888 Posting Maven

the master its not working

take your original program, and try changing your == comparisons to && comparisons

(and change your main function to read int main (void) to remove everyone's distress :P )

.

jephthah 1,888 Posting Maven

What's the difference between boolean and bitwise ?

well... y'see... dammit. nuthin' i reckon.

(* kicks rock *)

jephthah 1,888 Posting Maven

oops.

i meant to say, change it to if (color [b]&&[/b] 1)

tux4life commented: Haha! Your "Physic Powers" weren't working the way it should :P +7
jephthah 1,888 Posting Maven

for one thing, you're not reading and writing to your numerically sequenced files 'ifile' and 'ofile' like it appears that you think you are doing.

change it to the following

sprintf(ifile,"C:\\Document\\file%04d.dat",i);
sprintf(ofile,"C:\\Document\\o_file%04d.dat",i);

in = fopen(ifile,"rb");
out = fopen(ofile,"wb");

and you'll have to make the file name character arrays larger.


.

jephthah 1,888 Posting Maven

i'm going to use my Psychic Powers on this problem.

Monseiur Jephthah presciently knows that you need to change all of your conditional statements such as if(color ==1) ...

to the following: if(color [B]&[/B]=1) ...

and do NOT, as the post #5 suggest, use "else if" statements. if my Psychic Powers are correct, then you need to only use "if" statements.


.

jephthah 1,888 Posting Maven

you dont need to recalculate each and every factorial. because if you've already calculated 9! (for example), then 10! is really just 9! * 10.

and basically it's this: you can't do integer division. because all your quotients will be integer zeros.

3/6 = 0. 4/24 = 0. 5/120 = 0.

you have to use the "double" data type.

and as he already mentioned, it will crap out at 13!, because the maximum unsigned integer 2^32 = ~4 billion.

look into "long long int" data types. and "big number" libraries if you really need to get deep.

power series are not a trival matter in C.

jephthah 1,888 Posting Maven

^ from that page:

on linux you would just grep sysctl for a block of info

$ sysctl -a |grep therm
...

or query for the specific variable

$  sysctl hw.acpi.thermal.tz0.temperature
hw.acpi.thermal.tz0.temperature: 54.0C
tux4life commented: Good find! +7
jephthah 1,888 Posting Maven

i made also a find biggest and smallest but it alawys get last element

because for the smallest, you set num=1000 every single time you go through the loop. arr will always be less than 1000 each time, so it stores it in num, each time.


EDIT: i see William already re-wrote your code for you. consider yourself (un)lucky, because i would have made you fix it yourself.

jephthah 1,888 Posting Maven

div_t is struct for the result of divide operation, puts the quotient and the remainder into the structure.

it is being used here to convert a numeric value into an ascii string according to the base number system desired.

example: "itoa" convert value 1247 to be expressed as base-16 ascii string

itoa(1247,string,16);

1247 div 16 = quot 77, rem 15 ... 15 = "F"
  77 div 16 = quot  4, rem 13 ... 13 = "D"
   4 div 16 = quot  0, rem  4 ...  4 = "4"

when quot = 0, end do/while loop

final result of converting 1247 value to ascii base-16 number: "string" contains "4DF"


.

jephthah 1,888 Posting Maven

your problem is here: for(i=0;arr[i]<=3;i++) your index is 'i' yet your conditional is based on the value of 'arr' at the index 'i'

fix that.


.

jephthah 1,888 Posting Maven

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.

jephthah 1,888 Posting Maven

i have difficulties understanding your question.

jephthah 1,888 Posting Maven

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;
}
jephthah 1,888 Posting Maven

I think people should always buy local, when possible.

and with open source projects, you may be able to get most of what you need online


.

jephthah 1,888 Posting Maven

your post isnt really nonsense.

at least, it fits the question.

jephthah 1,888 Posting Maven

ORG (or sometimes, ".ORG" ) is an assembler directive.

assembler directives do not get translated into an instruction.

directives tell assembler *how* to assemble the source code into machine code. ORG sets the memory address at which the next instruction will be stored.

jephthah 1,888 Posting Maven

ORG declares the starting address where the code will be located in memory.

jephthah 1,888 Posting Maven

most of my experience is in manufacturing. i second AD's comment about being the "most interesting". we get to write programs that directly control hardware and physical equipment such as automation and robotics.... sometimes very heavy duty stuff like cranes and motor drives, sometimes very precise measurement and assembly equipment.

i am quite sure that working somewhere purely data/number crunching like a bank would bore the living crap out of me.

game programming might be fun for a moment, but even then i really think i would miss the hardware/equipment interfacing.

.

jephthah 1,888 Posting Maven

your first problem is that you're not getting the values entered by the user. this is becasue you're using the horrible function 'scanf()'

you could try to implement scanf in this manner:

printf( "Complex 1: Please enter two floating point values: " );
  scanf( "%lf %lf", &r, &i);
  printf(" you entered: %f and %f\n",r,i);

or, better yet, you would use 'fgets()' in conjunction with 'sprintf()' to perform some minimal error checkign on the input.

jephthah 1,888 Posting Maven

so if i got an infraction from Narue, do i get to claim my academic pedigree back to Dani?

jephthah 1,888 Posting Maven

this thread is relevant to my interests

jephthah 1,888 Posting Maven

theres no way to tell whats going on by the sparse amount of code you've posted.

the problem, i'll wager, is likely in your "load complex" function, whatever that is...

jephthah 1,888 Posting Maven

i think strchr is what you're looking for

it will point to the character in question. everything up to that character can be assumed* to be the characters of the first number, everything after can be assumed* to be the characters of the second number.

atol or strtol will accept the first one or more numeric characters and ignore non-numerics following thereafter.

*Definition: ass-u-me: the behavior often preceding an event where someone gets shot in the foot.

jephthah 1,888 Posting Maven

the prototype for itoa is: char * itoa ( int value, char * str, int base ); but it's really a bad function to use as it's not portable.

use sprintf, instead: sprintf(buf,"%d",sum); another problem you may be having is, how is "buf" terminated? what do you expect is at the buf[3] position?

jephthah 1,888 Posting Maven

either a sloppy abbreviation for "numbers" (abbr. "no.")

or he's looking for the LCM and GCF of two noses.

on further review, i prefer the latter.

Salem commented: Well it certainly "smells" like homework, so noses seems a likely bet ;) +30
jephthah 1,888 Posting Maven

yes.

yes you can.

jephthah 1,888 Posting Maven

right after the strip club my english sounds like native.

what are you saying, you can order a beer and a lap dance just like a good ol' boy?

your reputation as "creepy internet stalker dude", just keeps getting more and more entrenched.

seriously. do you know what "creepy" means? do you know why everyone describes you this way? you should look up synonyms, too. it's not a good thing to be.

you want some advice? quit hanging around losers at strip clubs. go take an english class at a community college. quit acting like a creep. maybe you'll even find a girlfriend or something.


.

jephthah 1,888 Posting Maven

you're increasing j++ every time it doesnt make a single character match within the key, which is messing your count up.

and its a bad idea to incrment a for loop counter within the loop itself unless you know what youre doing.

you should increment your pointers only after you've checked every single key character.

if there was a match then only increment the "input" pointer that reads along the string.

if there wasnt any matches out of all the key characters, then and only then do you copy the the input character to the output character, and also increment BOTH pointers.

jephthah 1,888 Posting Maven

HERE is how you do it:

use two pointers. an input and an output, both pointing to the start of the source string.

compare the input pointer character to each of your key characters. if you have a match, increment your input pointer only. if you dont have a match, then copy the input pointer character to the output pointer location, and increment BOTH pointers.

once you evaluate the last source character pointed to by the input pointer, NULL terminate the source string at the output pointer.

your source string now contains only the characters NOT matching any characters in your key. in other words, the key characters have all been removed from your source.


.

jephthah 1,888 Posting Maven

nm

jephthah 1,888 Posting Maven

cycle through each lettter in the alphabet, a through z, and check each letter if it repeats.

remember that ascii code character A is decimal 65 and Z is decimal 90. lowercase a is decimal 97 and lowercase z is 122. you can subtract 32 from any lowercase letter to get its uppercase version.

jephthah 1,888 Posting Maven

doh!

jephthah 1,888 Posting Maven

what if the user try to enter lots of no. and then press a key maybe "b" to stop and it generate the sum of all the users input

i think that's a good idea.

use a non-numeric character (like 'b' or whatever) as the sentinel to stop taking input

and if you want to get fancy, you could use the '+', '-', '=' characters as inputs to perform the functions you want to do.

i mean, isnt that what you're trying to do here? program a basic adding machine?


.

jephthah 1,888 Posting Maven

okay. sorry. his implementation of the basic sentinel concept is just fine.

but a calculator that spontaneously shuts down when you try to add 9999... well, it just isn't going to sell really well.

i'm just saying

jephthah 1,888 Posting Maven

that's dumb.

what if he wants to add 9999 as one of his numbers

jephthah 1,888 Posting Maven

this is retarded.

you won't get a reading from the free electrons in the air. you'll get a reading from the noise of the instrumentation pathway, which is deterministic.

now, i'm glad you're the hero of this 13-year-old's fantastical musings, but really, you ought to take your own advice about "spending your time on other things."

jephthah 1,888 Posting Maven

An example of this blah blah blah at any given point using some sort of analog device

or maybe you could sprinkle some magic fairy dust, and use some "sort of analog device" to aggregate the quantum velocities of the fairies at any given point according to Heisenfairy's Uncertainty Principle.

or you could just say fook it, and thow Schroedinger's cat into a lorenz attractor and save yourself a fair bit of math/sonic calculating, and call it 50/50.

:icon_rolleyes:


.

jephthah 1,888 Posting Maven

NO .... atol and strtol are not C++... they are part of the standard C library, <stdlib.h>.... understand that C++ is a "superset" of C. most everything in C is also in C++

so you dont have to manually convert each digit. I thought your variable was a single character, and that would have been the most simple way.

do feel free to go ahead and roll your own string-to-numeric converter if you like, there are worse things you could do, i suppose. but when you get tired of undefined behavior due to loosely written code, remember that a validated function is already available to you.


.

jephthah 1,888 Posting Maven

okay... i thought 'strVal' was a single character.... so, no you dont have to convert each character and multiply by the power of 10. that's the long way. use the standard libraries instead.

such as the function "atol()" (Ascii TO Long integer) or "strtol()" (STRing TO Long integer) ... either will convert a string to its numeric (integer) value

of course, Unsigned Long Max is 4294967295, so it would be meaningless for your strVal to have a length of more than 11 characters.

.

jephthah 1,888 Posting Maven

o wait. did you say strVal is a 1024 lenght character array??

that doesnt make sense....

how, exactly, is strVal defined?

jephthah 1,888 Posting Maven

seemingly random

there's your problem: nothing is truly random. some things are just less predictable than others.

the fact is, you're never goign to generate truly random numbers, even if something like that existed. so be happy with the commercially available pseudo-random number generators, like the rest of the world.

if you're doing something that needs more than that, then you're working for the NSA and shouldnt be trolling Daniweb for your answers.

tux4life commented: You're absolutely right :) ! +3
jephthah 1,888 Posting Maven

is strval a single char that is a numeral character between 0 - 9?

then you cant just recast it as an int.

to convert a character numeral to it's integer value, you have to subtract 0x30 (decimal 48) from the character (ascii) value. int value = (int)strVal - 48;