jephthah 1,888 Posting Maven

ive heard Python has a very simple USB interface too.

but that means it's written in C.

doesnt linux have a device filename for USB ports? like /dev/ugen something or other? cant you then do fopen( ) on that?

just thinking... ive never done it, myself.

jephthah 1,888 Posting Maven

sounds like you dont have the libraries installed. probably want to use your package manager (yum, pup, whatever) to get it.. you can get it straight from Subversion, if you dont mind trusting their malformed ssl certificate
https://svn.netfilter.org/netfilter/trunk/iptables/libipq/

you probably also need the <socket.h> header. this should be standard with gcc.

also check with these guys for related info
http://www.packetfactory.net/Projects/Libnet/

jephthah 1,888 Posting Maven

your "ReverseLetters" function doesnt work.

You had some other problems as well.

ive outlined one way you can approach this. now you need to (1) fix the "reverseLetters" function, then (2) write the palindrome detector.

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

void swap(int i, int j)
{
    int t;

    t=i;
    i=j;
    j=t;
}

int reverseString(char *str)
{
    int x = strlen(str); 
    int y;
    
    for(y=x; y >= (x/2)+1; y--) 
    {
        swap(str[x-y],str[y-1]);
    }
    return 0; 
}

void removeNonAlpha(char *str)
{
    char *str_ptr = str;
    int index=0;
    
    while(*str_ptr)
    {    
        if ((*str_ptr > 0x40 && *str_ptr < 0x5B) || 
                    (*str_ptr > 0x60 && *str_ptr < 0x7B))
            str[index++] = *str_ptr++;
        else
            str_ptr++;
    }
    str[index] = 0;
}
    
int printAllPalindromes(char *str)
{
    char origStr[100];
    
    strcpy(origStr,str);
    
    reverseString(str);
    printf("reversed letters : %s\n",str); 
       
    // use origStr and str to find palindromes
    
    printf("\nFound Palindromes: ????\n");
    return 0;
}
    
    
int main()
{

    char str[100];
    char *ptr;

    printf("Enter text string: ");
    fgets(str,99,stdin);
    
    removeNonAlpha(str);
    printf("removed non alpha: %s\n",str);
        
    ptr=str;
    while (*ptr) {
        *ptr = tolower(*ptr);
        *ptr++;
    }
    printf("changed to lower : %s\n",str);    
        
    printAllPalindromes(str);

}

another suggestion: don't use comments to explain what standard C library functions do. its annoying. everyone knows what a "for" loop does, what a "printf" statement does, and what a "return" statement does.

jephthah 1,888 Posting Maven

if "strtok( )" is not already a good friend of yours, you should become acquainted soon :P

jephthah 1,888 Posting Maven

step (1): connect to database

step (2): query database, according to your database API

step (3): read results returned from query

step (4): close database connection.


i don't know much about Oracle, but the MySQL API is here : http://dev.mysql.com/doc/refman/5.0/en/c.html

for MySQL, you will include the <mysql.h> and link to the libraries and use compiler-specific flags provided by the vendor (Sun). Oracle I'm sure is similar.

jephthah 1,888 Posting Maven

well, im glad to hear that it might be of help.

jephthah 1,888 Posting Maven

sigh.

kpnprakash, find the full source for diff, diff3, cmp, and sdiff here:
http://ftp.gnu.org/pub/gnu/diffutils/diffutils-2.8.1.tar.gz

download the archive, unpack it, run the command "./configure", then run the command "make" ... you will find the source code and compiled binaries in the "src" directory.

use the same software for linux or windows, but you may find additional info for windows installation here:
http://gnuwin32.sourceforge.net/packages/diffutils.htm

if you have more questions, the manual is here:
http://www.gnu.org/manual/.

HOWEVER....

i don't think this is going to help you much for your assignment.

good luck

jephthah 1,888 Posting Maven

Eve Was Framed

jephthah 1,888 Posting Maven

Possibly more than a support engineer. Why?

oh dear.

now it's going to be an e-peen contest. i'll bet you can write your name in the snow, too.

but you'll have to excuse my absence. I'll be busy studying for the P.E. exam. lucky you software engineers don't need to worry about all that silly electrical, chemical, mechanical, and materials stuff..

it's nasty business, really it is.

jephthah 1,888 Posting Maven

yes. you're quite welcome.

jephthah 1,888 Posting Maven

okay.

we'll be looking forward to your return.

jephthah 1,888 Posting Maven

thanks narue. what i posted was throwaway code just to debug why it wasnt writing to my file.

i don't /ever/ use exit(0); in the production... I instead write a message to the GUI and set the GUI to a certain state -- all of which would not help readability here... I also take more care with type casting (not that I would normally use a reference to %p outside throwaway code, anyhow.)

as for your notes about being careful with setting the errno outside a library loop, and using size_t len -- I have to admit I can be a bit sloppy... those are good suggestions for me to remember, thanks!

:)

jephthah 1,888 Posting Maven

.. any coding available?

i'd like to ask you the same thing.

jephthah 1,888 Posting Maven

i concur with narue.

the code you are trying to fix is practically complete.

the change you want to make to it is almost trivial.

the code that you have already, is clear and well-written, and follows a good basic style.

if you can't figure out how to make this change to the code you already have... i can't help you.

i can GIVE you the answer, but that would be counter productive.

Ive already given you a concise answer to the PIG LATIN question in the other thread, yet you cant even plop the function call into a main( ) routine.

i feel like im just giving you rope with which you will wind up hanging yourself.

you need to take a refresher class in basic C programming before attempting these more "advanced" concepts.

jephthah 1,888 Posting Maven

this is a complete mess. study this and see why it can not work, then fix it.

do 
{   
   gets(romanString);
   printf("Invalid input\n");
   printf("Please re-enter Roman number:");     

} while(romanString[j]!="I,V,X,L,C,D,M");
        
arabicValue=convert(romanString);
jephthah 1,888 Posting Maven

i must be missing something obvious.

fo'shizzle my nizzle: for (inx=1 ... in my defense, i was originally opening it as "rb+", later on in frustration i tried "ab+" ... '

did i mention that i just worked 65 hours this week, through the weekend. is that a valid excuse?

:icon_redface:

jephthah 1,888 Posting Maven

okay... so i'm feeling stupid here :P

its not writing anything to the file, at all. either at the position i thought (hoped?) it would, or at the end of the file.

the return values from either putc( ) or fprintf( ) indicate success, theres no errno code ... but its not writing anything. the file stays unmodified.

i have write permissions to the file in question.

i must be missing something obvious.

jephthah 1,888 Posting Maven

okay, where did you get the code from?

because I don't believe you wrote it.

jephthah 1,888 Posting Maven

yeah, dude... you can't just take a function like: int convert (char *) and turn it into your main routine

"convert( )" is a function that must be called INSIDE main, like this:

int main()
{
   blah   // setup
   blah
   blah
   blah

   scanf("%s",romanString);

   blah  // error-checking
   blah 
   blah 
   blah

   arabicValue = convert(romanString);

   printf("\nRoman  : %s\n",romanString);
   printf("\nArabic : %d\n",arabicValue);

   return 0;
}
jephthah 1,888 Posting Maven

okay, experts, i need help.

i can't seem to replace characters in a file, like i thought i would be able to:

here's an example code. i put print and error stuff in there to try and debug. everything seems to be working ... except that my filename is not modified.

any help greatly appreciated.

if ((fptr = fopen (filename, "ab+")) == NULL)
    {
        printf("File Open Error %s", filename);
        exit(0);
    }
    rewind (fptr);
    for (inx=1; inx<MTDF_HEAD_DURATION; inx++)   // looking for 10th line...
    {
        fgets (buf, 90, fptr);
        printf("%s (%p)\n",buf,fptr);
    }
    errno = 0;

    for (inx=0; inx<strlen(MTDF_Header.Duration); inx++)  // replace w/str "0001359"
    {
        result = putc (MTDF_Header.Duration[inx], fptr);
        printf("result: %d, errno: %d\n",result,errno);
    }
    fclose(fptr);
jephthah 1,888 Posting Maven

you cant change my "convert" function to main.

convert must be called BY main.

in main, you must get the string input from the user, do you error checking, and then display results.

jephthah 1,888 Posting Maven

first function depends on second. caller is responsible for error-checking input into "convert( )"

example : value = convert("mcmlxix");
returns: value = 1969

int convert(char *roman)
{
    int arabic = 0, tmp;
    char *str_p  = roman;
    
    while(*str_p)
    {
        tmp = letterValue(*str_p);
        if (letterValue(*++str_p) > tmp)
            arabic -= tmp;
        else
            arabic += tmp;
    }
    return arabic;
}
    
int letterValue(char letter)
{
    if (toupper(letter) == 'I') return 1;
    if (toupper(letter) == 'V') return 5;
    if (toupper(letter) == 'X') return 10;
    if (toupper(letter) == 'L') return 50;
    if (toupper(letter) == 'C') return 100;
    if (toupper(letter) == 'D') return 500;
    if (toupper(letter) == 'M') return 1000;
    return 0;
}
jephthah 1,888 Posting Maven

^ nice try. but you should have your opening tag be like this:

and you need to have all your INDENTATIONS (ie, "tabs") copied into the text box.... otherwise it still looks like shiite and we still can't read it.

but anyhow ... i opened your code, read it, and executed it... and im not sure why you're having a problem.

your code essentially works.

-------------------------------------

welcome to the Piglatin GeneratorType 'End' when finished

hello how are you wont you tell me your name

elloha owha reaa ouya ontwa ouya ellta ema ourya amena

------------------------------------

i mean, you're like 99% there. your code is very clear and straightforward.

are you telling me that you've done all this work, wrote all this very nice code and come this far, and [b]now[/b] you're [b]stuck[/b]?

what exactly are you having problems with? what function are you confused on? what are you trying to do that isn't working?[code=c]
and you need to have all your INDENTATIONS (ie, "tabs") copied into the text box.... otherwise it still looks like shiite and we still can't read it.


but anyhow ... i opened your code, read it, and executed it... and im not sure why you're having a problem.

your code essentially works.

-------------------------------------

welcome to the Piglatin GeneratorType 'End' when finished

hello how are you wont you tell me your name

elloha owha reaa ouya ontwa ouya ellta ema ourya amena

------------------------------------

jephthah 1,888 Posting Maven

i'll look at it...

but it sure would be a helluva lot easier on everyone if you were to just post your indented code between the code tags

you'd be a lot more likely to get people to help you if they can just read your code on the webpage without having to go through a lot of contortions.

jephthah 1,888 Posting Maven

insert your properly-indented code between code tags

[ code=c ]
insert code here
[ /code ]


(except, do not have any spaces within tag brackets... i just put those there so it wouldn't actually turn it into "code" ...)

jephthah 1,888 Posting Maven

glad you got your dos machine running for your class project. i imagine youve had a few frustrations with that.

Jephthah: "you just can not physically maintain an assembly line running dos."

Walt: "Maybe you can't, but it's obvious others have the knowledge to keep older O/S's running. They seem to be doing it."

Walt, have you even worked in an assembly plant environment???

I'm a line support engineer at a major facility that employs about 1000 semi-skilled assemblers and electronic technicians, and there is just NO WAY we can maintain assembly lines in a regulated environment using even Win 98, much less DOS.

we've got old Tektronics TDS-520 oscilloscopes in our automated test lines that are obsolete. Weve got RACAL switch matrixes that arent being manufactured or supported anymore, becasue the manufacturer, RACAL, doesn't even *exist* anymore.

these components need to be calibrated and serviced on regular intervals, and their replacement parts are not available. are you familiar with the term "end of life"?? these instruments need to be replaced. and here's the key: the available test instrumentation that we can get for replacements are not being manufactured for Win98, much less DOS, support. go on, ask Microsoft for some support on Win98 or DOS drivers.

now i'm not saying that there isn't some widget manufacturer out there who isn't keeping their deteriorating lines limping along, using a whole lot of spit and duct tape, scouring EBay and Craigslist for old equipment, and spending …

jephthah 1,888 Posting Maven

:eek:

jephthah 1,888 Posting Maven

you could consider using

\W+

instead of

\/ and \:

\W+ is any amount of non-alphanumerics. as opposed to \w+ which is any amount of alphanumerics (ie, 'A-Z' plus 'a-z' plus '0-9' plus '_' )

that way you wont be locked into certain exact type and amount of separators between your date and time elements. give you a little more flexibility to handle irregular input (inconsistency between users, and the like)

jephthah 1,888 Posting Maven

Bio Perl...

that looks like some pretty cool stuff

now i have a new diversion to poke around in :)

jephthah 1,888 Posting Maven

just be careful you dont let the smoke out of your video card.

that stuff's hard to put back in.

jephthah 1,888 Posting Maven

Thank the gods.

Someone finally answered this question that we've all been struggling with this for 4 1/2 long years,

what a relief.

someone let Tim know he can mark this as "solved"

jephthah 1,888 Posting Maven
#include <stdio.h>

main()
{
   int value;

   printf("enter any decimal value: ");
   scanf("%d",&value); 
   printf("value: decimal %d = hex %x\n", value, value);

   return 0;
}

thats all you have to do, right?

"int" doesnt have an inherent base. it's whatever you want it to be, whenever you want it to be.

or ....

are you specifically trying to convert it by hand as an exercise?

jephthah 1,888 Posting Maven

make your "firstUpper( )" function look like this. this is basically what Ancient Dragon suggested from the previous thread.

void firstUpper(char *buf)
{
    while (*buf)  // continue as long as characters avail
    {
        while(*buf == ' ')
            *buf++;         // skip all spaces until next char
        *buf = toupper(*buf);   // cap first char after space
        while(*buf && *buf != ' ')
            *buf++;         // skip all chars until next space
    }
}

you're using my original suggestion from that thread which, unfortunately, was flawed.

sorry for the confusion.

jephthah 1,888 Posting Maven

heres some more hints:

(1) do not attempt to look for "return" statements. at all.

(2) only use the open/close brace counting method.

(3) you need to change your regex method. merely looking for a brace at the beginning or end of the line WILL NOT cut it -- as you have already experienced.

(4) instead, look for ANY AND ALL braces, with the EXCEPTION of braces that are found within quotations (ie, braces to be printed.

this means that you can not just merely look for and count braces.... you have to look for and keep track of quotation marks ("), but disregard escaped quotation marks that are themselves being printed (\")

jephthah 1,888 Posting Maven

okay, yes, that's all well and good but as you'll see there's a perfectly reasonable explanation as to why I ...

oh, look. the Queen!

Aia commented: Long live the Queen. Hehe +7
jephthah 1,888 Posting Maven

lol. okay fine.

i'm a dork.

there. it's out now.

jephthah 1,888 Posting Maven

circular definition

a "poser" means one thing, except when it means "poseur" which is the definition you want.

look here, dadnabbit. i KNOW about "poseurs" ... i'm an expert in the art.

jephthah 1,888 Posting Maven

oh dear, what have i done.

jephthah 1,888 Posting Maven

(1) do not just blindly replace = with == , there was only one place where this was an issue if($openCount==$closeCount) (2) SOME functions can have NO "return" statements (void) ... but ANY function can have MANY returns (even void). you can NOT rely on the existence of "return" statements. if you try to, you will inevitably fail.

3) that is the very problem ive been telling you about. the method behind your choice of regex is flawed. this is the root of your problem. you need to think about another pattern by which you can find open and close braces without relying the "Beginning of Line" and "End of Line" operators (^ and $)

4) you probably have some whitespace (one or more spaces and/or tabs) after the brace. this is the same problem that is plaguing you in 3)

5) i dont understand what you mean

jephthah 1,888 Posting Maven

*pyr_p++ = 48 + (printNum-- % 10); Isn't that undefined behavior?

no, but i think i see why you think so.... pyramid was already defined as an array, and pyr_p is a pointer to that array

for simplicity's sake:

char pyramid[10000], *pyr_p;

pyr_p = pyramid;
jephthah 1,888 Posting Maven
jephthah 1,888 Posting Maven

friends don't let friends use AOL

not because of hacking. just because

jephthah 1,888 Posting Maven

Hulk angry

:icon_mrgreen:

jephthah 1,888 Posting Maven

man, you're gonna have to come off with a better description than that.

lets see your code, and we'll go from there.

jephthah 1,888 Posting Maven

i know what you're saying, dragon, but it doesn't usually work that way.

components reach end of life, instruments and machines are no longer supported, systems become obsolete, and drivers cease to be made available for their replacements. you just can not physically maintain an assembly line running dos.

last month i just bought a truckload of new industrial computers running XP to replace our ancient win98 machines. we couldn't keep those '98 lines going even if we wanted to, and believe me, management wanted to. 98 is long since end of life.

and we're not manufacturing cutting-edge devices. all our instrumentation automation is via GPIB for chrissakes. we'd run DOS if we could get away with it, for sure.


and... FTR... DOS is not an RTOS. Linux has RTOS capability, and Windows CE is an RTOS. but you dont need an RTOS to run the assembly line you described. its only useful for embedded development.

jephthah 1,888 Posting Maven

now walt, why you gotta keep hatin on my green dot? does it give you a rush of power?

hey, vardhani, heres a code segment that is 74% accurate and 81% helpful: change the line where "RANGE" is #define'd if you want to randomize from a different set of values.

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

#define RANGE 100  // for values from 0-99

int main()
{
   int myNum;
   char s[10];
   srand(time());   // "seeds" the generator
            
   while(1) // infinite loop (use CTRL-C to break)
   {     // reasonably random number between 0 and RANGE-1
        myNum = (int)((double)rand()/(((double)RAND_MAX + 1.0)/ (double)RANGE));
      printf("my random number is %02d", myNum);
      gets(s);   // just wait for <enter>
   }  // end while
   return 0;
}

whatever you do, don't let anyone tell you to use myNum = rand() % RANGE; if they tell you to use that, theyre either ignorant or trying to hurt you.

jephthah 1,888 Posting Maven

maybe these people are all from countries that blacklist Google's IPs

just wondering.

jephthah 1,888 Posting Maven

Oh, yeah, I'll be the first to admit, Turbo C is preferable. but it costs $$.

whereas the one i posted is a FREE alternative that's usually suitable for average user.

i mean think about it... DOS 5.0? whoever is hanging on to that crap is not likely to shell out much cash for new program development on what is probably non-critical, lowest priority legacy code.

as it is, it appears this is just a school exercise, anyhow

My program is simple so an example on hello world program would do the trick

I say Digital Mars will be entirely sufficient.

jephthah 1,888 Posting Maven

I can just imagine the stink you'll raise when I get around to actually reviewing your code

please do. i'm ready for a lesson. but stick to the "optimized" code please. the rest of the stuff was just so it would compile and work out of the box.

pyr_p = pyramid;

    //develop pyramid pattern
    for (i=1; i<=numLines; i++)
    {
        pyr_p += (numLines-i);
        printNum = i;
        while (printNum)
            *pyr_p++ = 48 + (printNum-- % 10);
        while (++printNum < i)
            *pyr_p++ = 48 + ((printNum+1) % 10);
        *pyr_p++ = '\n';
    }
    *pyr_p = 0;

    //print pyramid pattern to term
    printf("\n%s\n",pyramid);

You assumed he meant performance optimization.

Actually, I'm inclined to think that it's so far above the OP's head

i did assume speed optimization, so i assumed he would be interested in using pointers.

so i may have been wrong. meh. c`est la vie

jephthah 1,888 Posting Maven

o rly?

well, let's see now, shall we?

here's "poseur", which I say is the correct one in the context you used

po·seur [poh-zur; Fr. paw-zɶr]
–noun, plural -seurs [-zurz; Fr. -zɶr]
a person who attempts to impress others by assuming or affecting a manner, degree of elegance, sentiment, etc., other than his or her true one.
Based on the Random House Unabridged Dictionary, © Random House, Inc. 2006.

po·seur (pō-zɶr', pō'zər)
n. One who affects a particular attribute, attitude, or identity to impress or influence others.
The American Heritage® Dictionary of the English Language, Fourth Edition
Copyright © 2006 by Houghton Mifflin Company.

poseur
"one who practices affected attitudes," 1872, from Fr. poseur. The word is Eng. poser in Fr. garb, and thus could itself be considered an affectation.
Online Etymology Dictionary, © 2001 Douglas Harper

poseur
noun
a person who habitually pretends to be something he is not
WordNet® 3.0, © 2006 by Princeton University.

Now, lets look at "poser", which you say is -- somehow -- also correct.

pos·er1 /ˈpoʊzər/
–noun
a person who poses.
pos·er2 /ˈpoʊzər/
–noun
a question or problem that is puzzling or confusing.
Based on the Random House Unabridged Dictionary, © Random House, Inc. 2006.

pos·er 1 (pō'zər)
n. One who poses.
pos·er 2 (pō'zər)
n. A baffling question or problem.
The American Heritage® Dictionary of the English Language, Fourth Edition