jephthah 1,888 Posting Maven

is this an assignment for a C++ class? or something you're really trying to do in real life?

if this is a real application, I'd say you're using the wrong language and you should seriously consider Perl. Perl was made for this problem.

you'd have a complete solution that parses validated email addresses from a file in about 4 or 5 total lines of code.


.

jephthah 1,888 Posting Maven

I don't understand. Nobody in the US uses this crappy compiler with it's non-standard libraries. No one in the Western World seems to use this. even in second world countries in central and south america, they don't use this.

so how is it that Borland seems to have a complete lockdown on universities and tech schools all over India and a few Eastern European and Asian countries?

From what I've heard/read, kids in India are supposedly threatened with failure, if they attempt to use another compiler other than their institutionally-enforced Borland/Turbo/Whatever Piece Of Crap it is that they have.

how did this come about? maybe i'm a conspiracy nut, but, well... it seems like a conspiracy.

jephthah 1,888 Posting Maven

let me know what operating system you're using. I assume Windows XP.

If you happen to be using Turbo C on Linux (unimaginable, really, but i have heard tales), this will change the way we approach the whole problem.

jephthah 1,888 Posting Maven

Hello
I converted the source code of the English language. I program in php and mysql. I am programmed much of C and C + + and some of the things I know how it should be done in C and the other part of C + +. But I have to do this task only on C but I do not know how? For this I have done in C + +. I know that is not right to mix the two languages for programming. If someone can help me to do only the task of C.

it's nice that you converted your code comments to english -- not required but perhaps more people will not be easily confused or distracted.

and some people here will point to your use of "fflush(stdin)" and "gets", which are big no-no's, but you have a more fundamental problem.

your problem remains that you have a very implementation-specific program here, full of non-standard C code due to your choice of compiler, TurboC.

as a result, i can not compile or run or debug your program. and most people who would be able to help you, will have the same issue. Turbo C is just not used by professionals in the modern technical society. Microsoft Visual C++ and GCC have free compilers and are the industry standards, and there are many high quality free development environments that are compatible with these.

there's just no reason for anyone to …

jonsca commented: Nice response +1
William Hemsworth commented: yup +5
tux4life commented: Nice response +6
jephthah 1,888 Posting Maven

I dont really understand the logic here? Thats is gonna get into an infinite loop!

i believe you're right. she's trying to find when there's only one player left, but that isnt how to do it. the size of the structure is constant and greater than 1... i think the end condition should be when the current player's 'next' field points back to the current player.

but i believe narue called the source seg fault: the non allocated pointer.

i'm also suspicious of the line 29. i think the for condition should be i<(n-1) : the number of players, minus the 'first player' that was already allocated. But in any event, that's not related to the seg fault.


.

jephthah 1,888 Posting Maven

So I am trying to malloc the array in the following way, but I am still getting segfault errors if I try to access which means I am probably not doing it correctly. This is incredibly frustrating! Am I completely off base?

it looks right to me... although you know it's no longer necessary to cast calls to malloc since ISO C was introduced. And it's recommended that you don't.

as for the seg fault error, did you try adatapost's suggestion?


.

jephthah 1,888 Posting Maven

why don't you create a new thread, rephrased in a manner such that you have a question that can be both understood and answered.

just sayin'

jephthah 1,888 Posting Maven

holy indentation, batman! :icon_eek:

seriously, dude, i can't even look at that. you've got to properly indent that mess.


.

jephthah 1,888 Posting Maven

i dont know what your actual assignment says. but in any event you just can't use integer variables to declare array sizes. unless you dynamically allocate arrays, they are allocated at compile time and those variables are meaningless until runtime.

you can do something like this:

#define BLOCK_SIZE     4
#define NUM_SETS       2
#define BLOCKS_PER     1

int i, j;
cacheItem cache[BLOCK_SIZE*NUM_SETS][BLOCKS_PER];

//...

as to passing arguments, either pass constants as arguments directly, or use the #define'd constants as globals, or assign the local variables to the #define'd constant values before passing them.

you could also use "sizeof" to determine the size of the arrays during runtime.

finally, just a note, your "block size" and "number of sets" as separate entities seem to be a meaningless distinction -- you never use them individually, you always use them multiplied together.


.

kvprajapati commented: Good suggestion +6
jephthah 1,888 Posting Maven

Hi everybody,

so I need to give this huge proyect on monday.

well, you better get busy.

i need to write a program in c

okay, here's a start:

#include <stdio.h>

int main(void)
{
    // start coding here


    return 0;
}
jephthah 1,888 Posting Maven

it's not embedded, it's TurboC.

yes, it is toilet paper. and now, after two years, you just floated it back to the top of the bowl. Thanks :-/

jephthah 1,888 Posting Maven

I see so could this be a solution

you're using that "for" loop to do the function of a "while" loop. your 'counter' variable is meaningless. if you want a while loop, then just use a while loop.

another problem is that the two pointers are often not going to be pointing to '\0' (NULL character) at the same time. the memory locations after the terminating NULL are not guaranteed to be NULL. you could wind up with a big mess.

what happens when one string is longer than the other? one will be Null and one will not. why would you want to keep looping in that case? get out and determine which string ended. that string will be alphabetically "before" the other. e.g. "internets" comes after "internet"

If I subtract both strings would that just give me which word is longer? and I need them in alphabetical order.

no. you would get the difference between the two addresses, which would be meaningless.

"strlen" will give you the length of a string. since you're having to write your own "strcmp" function, you may not be allowed to use the <string.h> library. doesnt matter, though, because if you just use the while loop and jump out when the first string hits the end (the NULL character), you don't need to know the string lenght.

jephthah 1,888 Posting Maven

it would be nice to promote the latest threads which have not been replied to. This way people can see their thread still being alive instead of having to bump it for to keep on the first regular page.

f their thread is not being replied to, then there's probably a reason. like their question sucks, and they need to reformulate their question.

continuing to nudge them would only cause all the trash threads to float on the top like so much Atlantic sewage on the Jersey shoreline.

anyhow, we can easily see what threads are not replied to by the BIG RED ZERO in the replies column.

people who care about making sure all posts have been replied to in their forums, can easily click "next" page if they really need something to do.

Ezzaral commented: Completely agree. +0
jephthah 1,888 Posting Maven

maybe it was an unintended consequence of your awesomeness.

maybe it was an experiment, or a vanity project.

jephthah 1,888 Posting Maven

what does "No self-defined functions used" mean? that doesn't make any sense, so it seems to me you could just do this:

int compare_strings( char *str1, char *str2)
{
    return strcmp(str1, str2);
}

but that would be retarded to put a wrapper around a library function, and since this is (obviously) your homework assignment, i'm sure that's not what your instructor is looking for.

so you need to look at each character in each string and compare them against the other. if they all match, return zero. if they dont match, how do they not match? if the letter in str1 comes before str2 (alphabetically) then that letter in str1 will have a lower ascii value than the letter in str2

now, how are the letter stored in the strings in the first place? here's an example:

str1 = "Hello World"
str2 = "Hello Werds"

*str1 = 'H' = 0x48 (dec 72)
*str2 = 'H' = 0x48 (dec 72)

(*str1 +1) = 'e' = 0x65 (dec 101)
(*str2 +1) = 'e' = 0x65 (dec 101)

(*str1 + 5) = ' ' = 0x20 (dec 32)
(*str2 + 5) = ' ' = 0x20 (dec 32)

(*str1 + 7) = 'o' = 0x6F (dec 111)
(*str2 + 7) = 'e' = 0x65 (dec 101)

of course you dont cycle through each element using +1, +2, +3, etc. you will use the ++ increment operator to increment the …

xavier666 commented: The last C syntax is nice +0
jephthah 1,888 Posting Maven

Hi BGSPACE,

welcome to the forums. thanks for using code tags and explaining your problem.

my problem with your code, is that you've got quite a mix of different environments, you have some non-standard C, and you've also got some C++ functionality mixed in there.

the odd combination of <conio.h>, <sys/types.h> and <dirent.h> looks like you're using Borland's Turbo C. this is a terrible non-standard version of C and has been deprecated for going on 2 decades in most of the western world.

also, your use of <vector> is a C++ structure that is not C-language at all, and makes your program neither C nor C++ but some unfortunate hybrid.

Because you're using Turbo C with all it's non standard libraries, I'm afraid I can't help you. there's just no way i can even begin to compile your code on any standard C or C++ compiler. for the same reason, I suspect you will have a difficult time finding anyone else here who can help you beyond just visually inspecting your code for obvious errors.

the fact is, Borland's compilers are really crap and there are very few serious programmers who would ever use them. you will forever have difficulty as long as you continue to use it.

i strongly recommend that you toss it out and learn to use any of the following: GCC, MinGW, CodeBlocks, Bloodshed Dev C++, and/or Microsoft Visual C++. each of these are industry standard and are free, …

jephthah 1,888 Posting Maven

back off Mister 666, the poster has done nothing wrong.

there is no requirement that within the body of the code comments and output text be in English.

the forum rule you cite is to discourage pidgin english and leet speak, not to enforce some anglo-centric worldview. a large percentage of users here are NOT native english speakers.

bgspace does NOT have to rewrite his/her code to conform to your sensibilities. if you cant understand C code, then you need to quit "helping"

jephthah 1,888 Posting Maven

well, i learn something new every day.

The problem is named after Flavius Josephus, a Jewish historian living in the 1st century.

According to Josephus' account of the siege of Yodfat, he and his 40 comrade soldiers were trapped in a cave, surrounded by Romans. They chose suicide over capture and decided that they would form a circle and start killing themselves using a step of three.

Josephus states that by luck, or maybe by the hand of God, he and another man remained the last and gave up to the Romans.

jephthah 1,888 Posting Maven

another feckless attempt to steal teh fectorial codez.

jephthah 1,888 Posting Maven

consider the following:

typedef struct 
{
   char name[20];
   int memory;
   int time;
   int files;
} proceso;        // proceso is a "type" of struct
                  // defined as having the above elements
 
proceso titulos[MAX_TITLES] = {       // titulos is an instance of proceso
   {"Doom3", 500, 4,5},               // declared as an array
   {"Hades", 100, 2,1},               // and containing the following values
   {"Word" , 50, 1,1},
   {"FIFA" , 10, 3,1},
   {"Doom2", 400, 5,2},
// ...
// question:  how many is "MAX_TITLES" ?
};

//....
// print fields like so

for (i=0; i<MAX_TITLES; i++)
{
   printf("title name: %s (%d MB)\n",titulos[i].name, titulos[i].memory);
}

// etc...
jephthah 1,888 Posting Maven

I added mine because I thought I would be nice and supply you with an answer. Because also, your posted "solution" that "works" in Mandriva is not a viable solution: it's a platform specific workaround and an example of sloppy coding.

in any event, why are you complaining for getting help? you should be grateful that we're not letting you run with scissors.

fact is, Xavier666 is full of bad advice in a number of threads and I'm tired of seeing his "solutions". This one especially irks me because a moderator endorsed it.


.

jephthah 1,888 Posting Maven

We've already infracted two members on grounds of stalking and minor harassment.

OMG, ~s.o.s~!?

overzealous, much?

:icon_rolleyes:

jephthah 1,888 Posting Maven

Dear raghuhr84,

please disregard everything Xavier666 has said. anyone who suggests flushing the input buffer or using gets() has no business instructing anyone in the C language. (I'm also concerned as to why a moderator on this site (adatapost) would endorse his "solution" by giving him a green dot, but that's another issue.)

regarding your problem, I would recommend that for basic input, you use the "fgets()" function. "fgets" will get the input then you will parse it afterwards. "scanf()" has a lot of powerful functionality, but is susceptible to user error and can cause a lot of grief.

int main(void)
{
    char str1[100];
    char str2[100];

    printf("Enter 1st string\n");
    fgets(str1, 100, stdin);

    printf("Enter 2nd string\n");
    fgets(str2, 100, stdin);
  
    printf("1st string is %s\n", str1);
    printf("2nd string is %s\n", str2);
 
    return 0;
}

note this will have some problems if more than 99 characters are entered for a string. try entering 100 or more characters for string 1, and see the result.

this case can be accounted for with a few extra lines of code. i'll leave that for you to figure out.


.

jephthah 1,888 Posting Maven

What is this obsession with Tom Gunn, anyway? We already had a whole thread on this months ago

part of the wide-ranging conspiracy is that the original thread was locked down. the mods don't think you can handle the truth.

and FTR, the obsession is with Narue, duh. but i digress: Tom Gunn is Narue.

Q.E.D.


One of the reasons I don't outright confirm or deny the accusation is because it's so much fun to watch everyone speculate

well you sure did spend a lot of keystrokes attempting to explain away the mountain of circumstantial evidence against you ;-)

and by "everyone" I mean jephthah, since he seems to be the only one who really cares

don't confuse being my able to recognize your shenanigans with the source of the warm fuzzies you're feeling. sure i love you ... but you still can't call me Serkan. :D


.

jephthah 1,888 Posting Maven

so... for 5 solid years, our C/C++ Warrior Narue has been a regular poster averaging 4 posts per day (4.08 to be exact).

On June 21 2009, Narue disappears off the face of the Daniweb planet.

new guy Tom Gunn had joined Daniweb five days previously, on June 18. Tom Gunn hits the ground running. He maintains a posting rate identical to Narue's (3.99 posts per day) and almost immediately becomes a C/C++ superstar. For the next 5 months, he logs 681 posts, and racks up an incredible 1400+ rep points. Yes, that's right: 1479 reputation points in less than 5 months.

Then on 13 November, Tom Gunn abruptly disappears as quick as he appeared, vanishing into the ether with not so much as a "by your leave"

and less than 5 days later, Narue has fully resumed her previous posting frequency, picking up right where she left off.

Narue may point out that she had been posting during the time between 21 June and 18 November. But i point out that it was highly sporadic, sometimes just one post a week, sometimes up to a month without posting at all.

In fact, she posted absolutely nothing at all from June 21 to July 17... July 17th just so happened to be the very day that I posted this thread about Tom Gunn's uncanny resemblance to our C/C++ goddess

I submit this for your consideration. :)

jephthah 1,888 Posting Maven

I told you that was up to you. If i did that, you wouldn't have done anything. In fact, most members would probably think i've already given you too much code there.

YUP.

but to answer the OP's second question:

any loop can that can be done with a for statement, can also be done with a while statement. and vice versa. the details are different but the result will be the same.

rico.tee commented: answered my question clearly. +1
jephthah 1,888 Posting Maven

here's a bug: #include <conio.h> your program is worthless with that in it. why do you people insist on clinging onto that Turbo C crap?

jephthah 1,888 Posting Maven

What about posts which don't get solved or don't receive event a single reply? There have been instances of some good replies streaming in after as late as an year

...

okay, so it's the all-inclusive approach.

the rationale is that every so often someone has something useful to say, so we'll deal with 99 useless posts so we don't lose that 1 good one. i disagree with that rationale, but arguing it is now just a matter of preference.

so, that will be fine. but when i create my own online community, i'll do it differently. :P

~s.o.s~ commented: Oh, and do PM me the link if you create one ;-) +0
jonsca commented: JephthahWeb just doesn't have the same ring to it :) +0
jephthah 1,888 Posting Maven

M (1000) is the largest roman numeral.

Therefore, MMMDCCCLXXXVIII (3888) is the largest value that can be represented by roman numerals via standard rules.

above that value, you can use a bar over a number to indicate multiples of 1000. for instance IV with a bar over top of it equals 4 * 1000 = 4000.

this is not easy to do in ASCII, so an alternate is to put parenthesis around it: (IV) = 4 * 1000 = 4000. (CXLIV) = 144 * 1000 = 144,000, or the number of JW's who will get into heaven. the rest are apparently SOL. but i digress.

note that the romans didnt use the bar notation, this was invented in the Middle Ages. Romans just wrote out the number of M's necessary. not real convenient for scientific calculations, but since they didn't even have a zero, i don't think they really cared.

jephthah 1,888 Posting Maven

what are you talking about? drawings? in C?

i mean, you can name and save any kind of file you want, whether if its a .bin or .txt or .bmp or whatever, but really, if you're drawing pictures using C, you should be well beyond asking "how do i save a file" ...

so maybe i'm not understanding what you're asking.

jephthah 1,888 Posting Maven

Just because some dullard abuses a system that does not mean that the the system itself is bad, nor does it mean that the dullard is some kind of hero - it just means that someone has abused the system and as soon as we find out who it is (and Dani is now on the case, tracking them down) they can look forward to being banned from DaniWeb.

if your "system" requires constant vigilance from a team of lifeguards monitoring for people peeing in the pool, and manually booting them out every time another one does it, then that system is broken.

.

jephthah 1,888 Posting Maven

this is not a random bot or whatnot. someone is purposely targeting these people. i think it's obvious that they are doing so in order to highlight the absurdity of the arbitrary and anonymous voting system.

any skript kiddie can write a couple dozen lines of perl code to parse thru "user x" post history and downvote every single post. i could do it if i cared to. i don't do it because it's not my thing.

the point here, is that the whole up/down voting system -- as it is architected -- is broken at the most fundamental level.

to have any generic user be able to arbitrarily and anonymously alter another members permanent record -- even if "it doesn't really mean anything" -- is just asking for trouble. it's putting a big sign up inviting everyone to try and exploit the system.

Salem commented: Well said +0
Nick Evan commented: You appear to be right +0
Grn Xtrm commented: agreed +0
VernonDozier commented: Agree. Broken at the most fundamental level. +0
jephthah 1,888 Posting Maven

she's not supposed to be gone so long.

i miss getting beat up by her.

:(

jephthah 1,888 Posting Maven

you've got a lot of issues. for instance, these lines:

mino - minn = 30;
mino - minn = 60;
mino - minn = 00;

you can't make assignments like that. i'm having a really hard time following your logic, but you need to have the one variable being assigned on the LHS and the expression it gets assigned to on the RHS. like: mino = minn + 30 .

another thing is you have "car" as a type char (single character) then you later try to assign it the value 1.5. that's not going to work at all. you can only assign it char values, like: car = 'c'; or car = 'T'; or car = 0x63; // ascii for 'c' or car = 0x54; // ascii for 'T' there are other problems but i'm going to stop now

jephthah 1,888 Posting Maven

Dear colleagues I am currently working on _________ using Borland C.

with all the solid professional compilers and dev environments out there -- many of them absolutely free -- why anyone, anywhere still uses this pile of non-standard crap of a compiler, is beyond me.

it truly hurts my soul.


EDIT: and as A.D. pointed out, this is exceedingly complex. using buggy, non-standard, unportable Borland, you are just asking for even more trouble.

.

Aia commented: Good answer, spiced with passion. +7
jephthah 1,888 Posting Maven

I'd bring Dani, the cscgal.

jephthah 1,888 Posting Maven

. You might want to try turning off the firewall for a couple of minutes and then see if you can observe the same behavior

don't do it.

it's a trap.

Nick Evan commented: The cake is a lie.. +0
Ezzaral commented: shhhhhh... quit scaring them off. +0
nav33n commented: I don't remember asking you a goddamn thing! :P +0
jephthah 1,888 Posting Maven

i really want to help you, but your code is painful to look at. please repost it and enclose your code within [code] [/code] tags.

always use good coding practice like proper indention of code blocks, and do not put line numbers in front of each line, it only serves to make it less readable.

jephthah 1,888 Posting Maven

i think i'm going to go visit all of Bob's prior posts and upvote them all.

diafol commented: Back at you! Obviously p*ssed you off. Get a mod badge and stop licking brown.. +0
jephthah 1,888 Posting Maven

looking at the answers you have given to others


-- "Shut down your PC for 30 minutes every 4 hours"

-- "Save every 20 minutes when playing on-line games"

-- "You could have a miss-match or RAM"


it's obvious that bob is right: you dont know what you're talking about.

i would have told you the same thing.

jephthah 1,888 Posting Maven

if you would like to get a meaningful response, please consider the following:

How to Ask a Question

Please Use Code Tags

jephthah 1,888 Posting Maven

you can't do this:

if (ch == *my_word ||*my_word2 || *my_word3)

you have to specify what you're testing for each OR'ed condition.

if (ch == *my_word || ch == *my_word2 || ch == *my_word3)
jephthah 1,888 Posting Maven

and quit assuming everyone on here is a "sir". sexist language was deprecated last century. get with the program.

jephthah 1,888 Posting Maven

i think your changes are inspired by a lot of good ideas :)

but like some other i also think it has added the perception of too much clutter.

i think the most grievous offender is the row of "share this" "send that" "bookmark" "yadda yadda" buttons... I think they're ugly and extremely distracting/annoying. i would get rid of all that, because i never use any of that stuff. i think it would go a long way to cleaning up the clutter.

also, the arrow design for the up/down voting... the voting concept is cool, and i think will improve the site, but the arrow buttons are just ugly and stick out like a sore thumb. perhaps something more discrete, like small unobtrusive thumbs-up thumbs-down icons ... and also perhaps making the numeric for the up/down vote count a bit less prominent.

finally, I'm not happy that my rep power went to only +5. Maybe i would like it better if i could understand how the new rep-altering formula is calculated.

that's my $0.02

jephthah 1,888 Posting Maven

hi, that's a very nice cut-and-paste you've done.

did you use the mouse right-click to paste? or did you use CTRL-C and CTRL-V? i prefer using the keyboard myself, it seems much more efficient.

yellowSnow commented: Ah .. sarcasm is alive and well. I love it! +6
jephthah 1,888 Posting Maven

i agree that "void main" is to be avoided, but merely calling it "the evil" without explaining why is not going to impress many newbies, since it will always appear to them to work.

Anyhow, while "void main" may blow up a program in some future event, "scanf" will likely blow up a program here and now.

you should not advise beginners to use "scanf()" -- there's far too many pitfalls and unexpected behavior with that function. it's like using a chainsaw with no safety guards.

use "fgets()" instead.

tux4life commented: Thanks for the correction :) +20
jephthah 1,888 Posting Maven

the main() program can often be called by a parent program. 'return 0;' indicates to the caller (parent) that the main() program executed correctly.

so... generally speaking, the main function must be of type 'int' and therefore must return some integer value on completion. zero (0) is the standard "successful" return value (think: returned with zero errors) although it could be some other value that indicates an error state, depending on the caller

if main does not return a value (like the case of 'void main()' ) then you are now in the realm of "undefined behavior" when the program is called by another. Undefined behavior is almost always a Bad Thing.

.

no1zson commented: great explanation +3
Salem commented: Hell yeah - I had to deal with a "void mainer's" prog once, the exit status was even worse than rand() +36
jephthah 1,888 Posting Maven

page 5

sknake commented: it made me lawl +6
jephthah 1,888 Posting Maven

alberton, generally speaking you can't just go and grab some missing header file off the interwebs and expect it to work. these types of headers are often built for your system, and even if you got a header file to work, you'd likely find yourself in an sequential procession of one missing header file after another.

so.. what Nick and Wildgoose said. go build (or rebuild) the development environment source files correctly.

Salem commented: Absolutely! +36
jephthah 1,888 Posting Maven

to post in this thread, wins.