jephthah 1,888 Posting Maven

this is what i was thinking.

void neuter(CAT *this_cat)                 // you dont need to return an int.
{                                          // note also, we can call the char pointer any name
                                           // we want as long as we're consistent in its use.

    if (strcmp(this_cat->name, "Betty") == 0)
    {
        printf("Hey get off me you crazy freak, my name is Betty!   Duh??\n");
        this_cat->neuter = TRUE;                // for lack of a better category
    }

    else if (this_cat->neutered == TRUE)        // already neutered
    {
        printf("Yo, you best open your eyes and step off my grill, dawg!\n");
    }

    else if (this_cat->neutered == FALSE)       // now it's party time
    {
        printf("RRRRROOOWWWWLLL!  PFFFZZZZTTT!   YOOWwwwlll...\n");
        this_cat->neuter = TRUE;                // and the deed is done  :-(
    }

    return;                                     // no need to return an int, 
                                                // the struct is already modified
}
jephthah 1,888 Posting Maven

umm, so then what's wrong with char map[10][10]; ?

jephthah 1,888 Posting Maven

This is a small project for school but I perfer that it stay standard so it can run on Windows, OSX, and Linux as I on a personal level use Windows AND Linux.

then stay away from "conio" or any similar libraries. otherwise trying to maintain cross-platform portability you're going to have a LOT of extra work. and by "a LOT" i really mean A LOT.

Now some program functions are worth that extra effort. But conio -- with its blinky screen text, colors, and unbuffered keyboard hits, -- is not.

If you want it to stay standard, then stick with standard libraries. Like Walt said, use "getchar()". Use any functions in the <stdio.h> and <stdlib.h> libraries. They will all be portable across all systems.


.

jephthah 1,888 Posting Maven

sorry, your question is not urgent.

and the fact that you have spammed it here multiple time, now just moved you to the very back of the queue.

jephthah 1,888 Posting Maven

I need your help AT ONCE plz IN C CODE ONLY

... NOW write equation like this

yeah, i'm gonna suggest that you rethink how you phrase requests.

I dont know about your native language, but in English language when you are requesting for someone to help you, and you use the IMPERATIVE tone as an ORDER ... well, you're just going to get everyone pissed off at you and no one will help.

good night, and good luck.

Salem commented: "Romanes eunt domus" +20
jephthah 1,888 Posting Maven

here's a simple answer:

a "hash function" takes a string of an arbitrary and probably variable length (called the key) , and transforms it into a single integer (called the hash value) which is a smaller, fixed width value.

hash functions are widely used in cryptography and database management, for two examples.

there's an endless number of methods to write a hash function, so we can't give you an example in C without knowing the requirements. and we wouldn't anyhow, because writing the C code is your job.

so now you need to start writing some code according you your assignment, and once youve got some code written, and have a specific coherent question about the code or how to implement a particular aspect of your assignment, you can come here and maybe get an answer.


.

jephthah 1,888 Posting Maven

you're gonna have to give us some more to work with here. lets see this window that you created using C. post the code. preferrably you will use code tags and post code that compiles.

jephthah 1,888 Posting Maven

just another point to consider. MMU is a member of the Association of Southeast Asian Institutions of Higher Learning which includes major universities around the world.

if you got a BSc degree from MMU and did well (like honors grad) you could get scholarships to do grad school at most any college in the US, UK, Canada, Japan, Australia, Phillipines, etc. etc.

i'm not trying to promote this university above any others, i'm just saying it's legitimate, and you would not do bad to go there.

I'm sure there are reasons why someone might say a "traditional" university in malaysia is "better" but i don't know enough about any of them to comment.

jephthah 1,888 Posting Maven

well, here's my stripped down version :)

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

int main(int argc, char **argv) 
{
    int i, days_In_Month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31} ;	
    char *month[12] = {"January",   "February", "March",    "April", 
                       "May",       "June",     "July",     "August", 
                       "September", "October",  "November", "December"} ;	
	
    for (i = 0; i < 12; i++)
        printf("%s has %d days.\n", month[i], days_In_Month[i]);

    return EXIT_SUCCESS;
}
jephthah 1,888 Posting Maven

sorry for the simplistic question, but have you tried to resize your screen resolution?

jephthah 1,888 Posting Maven

okay, i'm a new user who just logged in to make my very first post ever, because i found some old thread on google, and i'm prepared to dazzle the world with my "solution" on how to best "gets()" input from the terminal.

i'm already ignoring the bold text on the message input that says the same thing. why would a popup be any different?

just lock the stale threads down. random posts 3 years after the fact don't contribute anything, they just make this site look like its full of retards to anyone who finds it afterwards.

jephthah 1,888 Posting Maven

I know it's good and your information really helps , but I just don't know whether it is really world recognised or not ( the colleges or universities usually will only tell how good their school are and keep promoting their school , sometimes it just happens that the truth is not as good as what they are telling :( )

they have a large faculty consisting of professors, lecturers and researchers from all over the world. many PhDs from recognized universities in the US, UK, Japan and Australia. they are private, which probably means more expensive, but they are legitimate because they are a real research institution and not a "for-profit" corporation.

as to being world recognized, that's only an issue as to the accreditation. and yes, they are accredited. My concern with MMU would be that they are a young institution and will inevitably experience "growing pains". but they are recognized by international ratings organizations using international standards. If their young age is a concern, there are other universities in Malaysia that are more "traditional". any of them would be fine.

just stay away from for-profit diploma mills like NIIT.

jephthah 1,888 Posting Maven

i dont understand what you're trying to accomplish. it's not clear to me.

in your first post, you did refer to an old link, but to be honest, i'm not going to search through several pages of some old discussion to try and guess what you may have gotten out of it.

so, i think this is part of your problem here, that some people can get frustrated when problems aren't explained clearly. don't take it personal. i see that you were just trying to get to the point, but remember that we're not thinking about this problem like you are, so you need to back up and attempt to clearly explain the issue in as concise a manner as possible.

Now if i just make a guess about your current issue: it seems like youve got a problem in the second loop starting at line 26, such that you will never save any character if it ever matches another character. i'm not sure if that's what you intend to do.

jephthah 1,888 Posting Maven

I know that reference means a pointer but I'm not sure on how to write the code for it. He has given us no examples. I am so lost. :(

okay, let's start over, shall we? start off with small steps, follow the instructions and get the first parts working before trying to do the rest. dont try and get it all done at once.

you already had A. I'm going to fix your code so that you now have B and C. notice what i've done, and try working from here.

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

#define   TRUE 1
#define   FALSE 0

typedef struct {
	char name[10];
	int weight;
	int neutered;
} CAT;

void printCat (CAT *cat_ptr);           // passing by reference
void neuter   (CAT *cat_ptr);

char *names[6] = {"Fluffy" , "Tigger", "Max", "Betty", "Cat-27" , "Jake"};

int main (void)                         // main type is always "int"
{
    CAT *pMax;                          // declare a pointer

    pMax = malloc(sizeof(CAT));         // then allocate one CAT on heap

    strcpy(pMax->name,  names[2]);      // set name, weight, neuter to fixed values
    pMax->weight     =  12;
    pMax->neutered   =  FALSE;

    printCat(pMax);                     // print the one cat's info
    neuter(pMax);                       // neuter it
    printCat(pMax);                     // reprint the cat's info

    printf("\n\nhit Enter to quit.\n");     // in case window closes automatically.
    getchar();

    return 0;
}

void printCat(CAT *cat_ptr)
{
    printf("\n   NAME       WEIGHT      NEUTER    \n");
    printf("----------  ----------  ----------  \n");
    printf("%10s      %2d          ", cat_ptr->name, cat_ptr->weight);

    if (cat_ptr->neutered == TRUE)
        printf("Yes\n");
    else
        printf("No\n");

    return;
}

void neuter(CAT *cat_ptr)
{
    printf("\n...Im in ur funshun …
jephthah 1,888 Posting Maven

you want to extract part of a string from within a string. the fact that this string is in a linked list is irrelevant. ask yourself the same question, but generalized: "How do i pick part of the data from the string? "

example: strncpy(&origString[10], subString, 5); will get bytes 10-14 of the origString and put it into subString.

jephthah 1,888 Posting Maven

something's not right, here. how are you gonna neuter a cat named "Betty" ?

:S

Aia commented: It became Betty after the operation. Haha! +8
jonsca commented: Dude, FTW +4
WaltP commented: The same you neuter my dog named Rex, since she squats to pee. :P +11
jephthah 1,888 Posting Maven

Thanks again , and have you heard of Multimedia University from Malaysia ?

MMU is a relatively young private university, but has already established a well-regarded reputation. They have large modern facilities, and they have a sizeable pool of PhDs professors who do real, funded research. Just looking at their Faculty of Engineering, I see that MMU professors, lecturers, and researchers are drawn from credible academic institutions all over the globe.

It appears to be a good choice. I would recommend anyone to attend this university instead of the for-profit diploma mill, NIIT. And as a Malaysian, you would probably feel more pride attending this school, as well.


EDIT: note, the difference between "private" and "for-profit", these are very different types of institutions. some of the best U.S. universities are private, along with many notable public ones. by far, the worst U.S. "universities" are for-profit.

.

jephthah 1,888 Posting Maven

every one of these jokes are terrible.

i want my 2 minutes back.

jephthah 1,888 Posting Maven

I personally wanted to use getch and getche

forget getch and getche ever existed. the need for unbuffered terminal input has become obviated since the widespread adoption of GUIs, like, about 15 to 20 years ago.


or dont, and hobble yourself with reliance on non-standard, non-portable library functions that will render your code unusable on most systems other than your own.


.

jephthah 1,888 Posting Maven

Wow thats just lovely on the "return" statement in line 20 part. My professor is the one that told me to put it there.

i would suggest that either you misunderstood your professor, or your professor misunderstood what you were doing.

jephthah 1,888 Posting Maven

you're putting single quotes around a numeric value. don't do that.

single quotes frame a single ascii character. double quotes frame an ascii string. if you want to compare a numeric, then just put the numeric without any quotes.

'A' is the character for the letter A. it has a value of \x41 or decimal 65.

'65' is undefined. single quotes are for one and only one character. who knows how this will be interpreted! Maybe it will be interpreted as the first character, '6', which is the ascii character having the value of \x36 or decimal 54.

"65" on the other hand is a string, having the value \x36\x35\x00


Look at an ascii chart. any single ascii character as a 'char' data type is inherently represented as an 8-bit integer value. the 'char' and it's integer value are fundamentally identical to each other.

the ascii char 'A' equals 65 equals the ascii char 'A'. the ascii char 'B' equals 66 equals the ascii char 'B'. the ascii char 'Z' equals 90 equals the ascii char 'Z'

65 <= 66 <= 90 --> TRUE

'A' <= 'B' <= 'Z' --> TRUE


.

jephthah 1,888 Posting Maven

look, heres a quick-and-dirty way to get an integer from input, using fgets().

char buffer[32];
int number;

do {
   printf("enter integer : ");
   fflush(stdout);                         // needed because no newline char
   fgets(buffer, sizeof(buffer), stdin);   // get string input
   number = atoi(buffer);                  // converts integer found in string
   if (number == 0)                        // if no conversion was made
      printf("Invalid Input!  ");          // then print warning and repeat
} while (number != 0);

printf("you entered the number '%d'\n", number);

this does very minimal error checking and will not accept the value of zero (0). It just ignores any non-numeric characters after a valid value. If you enter more than 31 characters you will have problems with extra characters remaining in the input buffer.

i personally do not like using "atoi()" and i would prefer a robust method using "strtol()" and full error checking, but you've got enough issues to deal with at the moment.

so it will do for now.

jephthah 1,888 Posting Maven

sorry you're having so much trouble. i'm afraid i have no idea about converting old borland graphics libraries. i avoid ever using them in the first place.

at leas this can serve as a warning to others, to stay clear of developing on Turbo C, especially with the antiquated graphics or conio libraries. there are libraries that attempt to recreate these functions for other compilers, but they always have problems.

if you stick to coding in standard C, you'll avoid thes problem. if you need to go outside the standard, then use modern portable libraries and modern compilers.

jephthah 1,888 Posting Maven

i'm having a hard time following your question... what exactly are you trying to do?

one thing you should know that will help you, is you don't need to cast each char as an int just to do a comparison to a constant value. a char type is essentially just an 8-bit integer, so you can directly compare it to some constant numeric value. for instance, check out this snippet that converts all lowercase to uppercase:

char myString[32] = {"This... is 1 Example String!"};
int length,  i;

printf("original string : %s\n", myString);

length = strlen(myString);
for (i = 0; i < length; i++)
   if (myString[i] > 96 && myString[i] < 123)  // if char is lowercase
      myString[i] -= 32;                       // convert to uppercase

printf("modified string : %s\n", myString);

.

jephthah 1,888 Posting Maven

think ardav meant that other people's references to the old username will remain within the body of the text.

like i change my name to "joe schmoe" and all my old posts are now listed as being "joe schmoe" but other people's posts will still be addressing me as "jephthah".

it will cause consternation when internet archaeologists of the 22nd century attempt to reconstruct our "original intent"

there will probably be a schism between scholars over the Daniweb Apocrypha

WaltP commented: Good description... +0
jephthah 1,888 Posting Maven

well, then, you need to print some spaces at the beginning of each line before each number.

how many spaces do you print?

it depends on the length of the number.

think about how you're going to accomplish this.

jephthah 1,888 Posting Maven

these are warnings, not errors. meaning your program will compile and run (for a while), but probably will not work as expected because you're doing something unusual.

first one is you're assigning an int (length) to the char array (input_buffer).

before we can fix it, we've got to know what are you trying to do in the first place? are you trying to find the length of the string? then you need to use a function like "strlen()"

second one is just simply that you have a variable (cur_pos) that is not being used anywhere. the warning is in case you meant to use it but forgot. either delete it entirely or fix your code to use it.

another problem i see is the "return" statement in line 20. everything after that is meaningless because it will never get executed anyhow.

jephthah 1,888 Posting Maven

changing color of text is not a C-language function.

if the Intel Compiler has this capability, it is a "compiler extension". you will have to find the documentation for the compiler and research how this is accomplished.

be advised that any solution you find will not be portable, and will likely not work as expected on any system other than your own.

jephthah 1,888 Posting Maven

what are you asking? you said you had compile errors. i'm saying you need to include the

-lpthread

switch to link the pthread library. if you follow my commandline instruction in my previous post, your program will compile and run successfully, without any compile or runtime errors.

now is it a successful solution to the classic resource problem? i don't know, you need to figure that part out.

jephthah 1,888 Posting Maven

gcc -lpthread -o dining dining.c works for me ;)

jephthah 1,888 Posting Maven

for one thing you're getting characters into 'c' and parsing results based on something called 'answer'

jephthah 1,888 Posting Maven

don't worry about it, it's all good. :)
.

jephthah 1,888 Posting Maven

well, they'll have different algorithms of course, but yes, you have to pay attention to your loops so that they iterate the proper number of times.

also, make sure any constant numbers found in a floating point formula have a decimal point in it even if it's a round number to be sure that it's not calculated as an integer and drop the fractional part. like using 1.0/i instead of 1/i

.

jephthah 1,888 Posting Maven

most other sites have the courtesy to close their stale threads. they leave them available for archive purposes, but not allow them to become magnets for spammers, trolls, and other assorted retards.

allowing flotsam and jetsam from the internets to collect around old posts only serves to make the Daniweb site look incompetent . Passers-by from google links see our popular "Solved" threads with ridiculous "answers" and/or insipid commentary as final posts, sometimes pages worth.

if that's the kind of image you want to project, that of "inmates running the asylum", then keeping the threads open forever is the way to go.

jephthah 1,888 Posting Maven

because you're calculating the harmonic series incorrectly.

when you try to calculate the finite summation of 1/n for all n from 1 to N, you need to only go to N... not N+1.

when you try N=5 the result should be 2.283333 but you're getting the result for N=6 which is 2.450


.

jephthah 1,888 Posting Maven

for (;;) just means "forever". typically used for a loop that will execute an indeterminate number of times, exiting with a break; command once the exit condition is found.

the corresponding while would be while(1) or while(TRUE) ... doesnt make any sense to use '\n', even though technically '\n' is non-zero and it will work. it just looks really weird and implies that the programmer doesn't know what they're doing.

the second for loop is a bad example. this will be a source of problems. i can't just convert this to a while loop, because the while loop will then be faulty.

think about what that for loop is doing.... what will it execute if the DEBUG is defined? what will the for loop execute if the DEBUG is not defined? see the problem?

in any event, you'll want to get the character 'c' first, then evaluate it if it is '\n' or EOF to decide whether to conditionally execute the loop or exit.. how you structure your loop may also depend on what you're doing with 'c'

.

jephthah 1,888 Posting Maven

try changing your summation line to ensure a floating point value is being calculated correctly

sum = sum + 1.0 / i;

the way it is, "1/i" will always evaluate as an int, and then be added to the double. Although i'm not certain why your result is zero, because 1/1 = 1...

anyhow, i notice you've spelled "include" wrong in your #include <stdio.h> statement. probably that's just a typo when you posted it here and not in your actual code.

jephthah 1,888 Posting Maven

I don't know why, but every time i see this thread title Memento comes to mind. maybe it's because i just cant remember any other titles.

Ha ha. get it? I cant remember them!! LOL. you know, remember any ...

oh, never mind.

jonsca commented: Wait, what do you mean? +0
Aia commented: Look at the tatoo in you arm. ;) +0
jephthah 1,888 Posting Maven

oops.

jephthah 1,888 Posting Maven

please check the dates before posting. youre responding to someone who posted over two years ago, who was posting to someone else from four years prior to that.

nobody cares about this thread or is paying attention, all its doing now is cluttering forum space and wasting time.

jephthah 1,888 Posting Maven

I shall never think of it either.

And let us never speak of it again.

jephthah 1,888 Posting Maven

hi, and welcome. your english is great! just from your intro, you could have passed for a native speaker.

anyhow, don't worry about it, there are a lot of international people here, and very many of them have difficulties with english. it's not a requirement that you be fluent, just to try.

jephthah 1,888 Posting Maven

Welcome Jim!

quite an impressive resume. glad to have you here. help is what we do. :)

jephthah 1,888 Posting Maven

welcome Jeff! good luck in your Masters' program.

jephthah 1,888 Posting Maven

welcome! go to C++ forums and take a shot. be glad to have you :)

jephthah 1,888 Posting Maven

no ones insulting you dude. in fact, we'd really love to help you. Don't worry about Walt, he's often cranky, it's not personal.

but think about it. you've come into a C forum, and dumped a pile of C++ code, with a vague comment for "someone check this out" or "give assistance"

i mean, what do you want us to do for you? you haven't asked a question that can be answered. where are you stuck? what problem are you having? what is not working? what are you trying to do?

we're not mindreaders.

and anyhow, you cant delete accounts here. they will last into perpetuity. ;)

.

WaltP commented: I wasn't cranky, I was stating a fact, and a conjecture. -2
jephthah 1,888 Posting Maven

so whats you point really?

actually, that's what they're trying to figure out from you.

you have yet to ask a question.

jephthah 1,888 Posting Maven

I need to have an equilateral Triangle shape in the output.

hold on, your example triangle you posted, with spaces replacing the dashes, you said you wanted it to look like this:

1
  12
 345
6789

this example is not an equilateral triangle. it's a right triangle, that is right-justified, whereas what youre getting currently is a left-justified one.

1
12
345
6789

an equilateral triangle would look like this

1
 234
56789

now which one do you want?


.

jephthah 1,888 Posting Maven

this is C++ code, so it's not going to work on a C compiler. You may already be aware of this, but I'm just sayin'

jephthah 1,888 Posting Maven

You could be right there. Replace Google search with DaniWeb search in that equation. Maybe this is something Dani could take a look at when the current site update stuff is out of the way.

or maybe she could "take a look" at auto-locking old threads, that can only be re-opened upon legitimate request to a moderator.

would be easy to implement, will quit appending bullshit answers to solved threads, quit wasting moderators time locking and deleting the swarms of one-off "me toos" and "gimmetehcodez" posters.

it would also save the rest of us from crafting detailed responses to the OP, thinking it's a current thread, only to find out afterwards that the damn thing is five years old. i don't know how many times i've done that, it's really aggravating.

diafol commented: here here +0
Ancient Dragon commented: Agree +0