deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the type is unknown, try using Object^. Provided you're working with CLI types, they're all derived from Object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but if my txt file is wrriten like this:

That's fine then.

its stiil dont do the math

That file works for me (assuming the -->rented and -->not rented parts are exposition added by you for the post and not actually in the file. If they're in the file then you need to remove them from the stream:

#include <stdio.h>

int main(void)
{
    struct rental {
        char name[20];
        int year;
        int inout;
    } movies[20];

    FILE *in = fopen("test.txt", "r");

    if (in) {
        size_t i, n, sum = 0;
        int ch;

        for (n = 0; n < 20; n++) {
            if (fscanf(in, "%19[^\n] %d %d ", movies[n].name, &movies[n].year, &movies[n].inout) != 3) {
                break;
            }

            while ((ch = getc(in)) != '\n' && ch != EOF)
                ;
        }

        fclose(in);

        for (i = 0; i < n; i++) {
            sum += movies[i].inout;
        }

        printf("Available movie count: %d\n", sum);
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

priceperbushel is a double, not an int. Actually, I'd recommend using double everywhere you use float too. You also have a rogue semicolon in getProfit() that's breaking the loop.

Consider this:

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

double getProfit(double bushels[], double price);
double getCosts(double acres[], double totalAcres, double cost);

int main()
{
    double acres [20];
    double bushels [20];
    double cost;
    double pricePerBushel;
    double totalAcres = 0;
    char choice;
    int count = 0;

    for(count = 0; count < 20; count++)
    {
        acres[count] = 0;
        bushels[count] = 0;
    }

    count = 0;

    printf("\nwould you like to add anouther field:");
    scanf("%c", &choice);
    getchar();

    while(choice != 'n')
    {
        printf("\nEnter the number of acres:");
        scanf("%lf", &acres[count]);
        getchar();
        totalAcres += acres[count];

        printf("\nEnter the number of bushels:");
        scanf("%lf", &bushels[count]);
        getchar();

        printf("\nwould you like to add anouther field:");
        scanf("%c", &choice);
        getchar();

        if(count == 19)
        {
            printf("\nyou cannot add any more fields");
            choice = 'n';
        }
        count++;
    }   // end of loop

    printf("\nenter total bills:");
    scanf("%lf",&cost);
    cost = getCosts(acres, totalAcres, cost );

    printf("\nenter the price per bushel:");
    scanf("%lf", &pricePerBushel);
    getProfit(bushels, pricePerBushel);

    int i = 0;

    for(i = 0; i < count; i++)
    {
        bushels[i] = bushels[i]-(acres[i]*cost);
        printf("the profit for the field #%d is %f \n", i,bushels[i]);
    }

    return 0;
}

double getCosts(double acres[], double totalAcres, double cost)
{
    int i = 0;

    cost= cost/totalAcres;

    return cost;
}

double getProfit(double bushels[], double price)
{
    double temp = 0;
    int i = 0;
    for(i = 0; i < 20; i++)
    {
        temp = bushels[i];
        temp = temp * price;
        bushels[i] = temp;
    }

    return …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon can you please explain the printf statement?

This is the point where I'll suggest that you RTFM, because format strings are clearly and completely described. But, I'll also explain it.

The %g specifier selects the behavior of either the %f or %e specifier (that's fixed or scientific format, respectively), depending on the actual value being printed. By default, if the exponent in your value exceeds 6 or -4, %g uses scientific format rather than fixed format. Trailing zeros are omitted, which is behavior you want (%f doesn't provide this).

When you provide a precision to the specifier (a dot followed by a numeric value), %g treats that as a maximum number of significant digits, which means both whole number digits and precision digits. For example, the value 123.456 has six significant digits. IF you try to print it with printf("%.4g", 123.456), you'll get 123.4 as output.

The numeric value in the precision can be a placeholder for an argument rather than a literal value in the string, that's what the asterisk does. It says "take the next argument to printf() and use that value as the precision". Another way of writing the example above using a placeholder would be printf("%.*g", 4, 123.456).

All in all, what my example does is calculate the number of digits in the whole value, then adds 8 to this (where 8 corresponds to the number of precision digits you want), then uses that value as the significant digits for the %g specifier. …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pay special attention to the "precision" and "field width" specs above.

No disrespect, but unless I'm misreading your post (in which case I apologise) you should follow your own advice. ;) The %f specifier doesn't remove trailing zeros when the precision exceeds the value, and the precision on the %g specifier affects significant digits rather than digits after the radix. So while %g can be used to get the correct behavior, that's only after doing introspection on the value to determine how many whole digits are present:

#include <stdio.h>
#include <math.h>

int main(void)
{
    double a = 1234.567891234;

    // Quick and dirty digit count
    int digits = log10((double)(int)a) + 1;

    printf("%.*g\n", 8 + digits, a);

    return 0;
}
rubberman commented: Good point - haven't had to deal with this cruft in 20 years! :-) +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's no longer embedded in the post, but the file is still attached. You can remove it entirely through the same process that you added it:

  1. Edit the post
  2. Click the Files button
  3. Click the 'Delete' link next to the attached image (where the embed buttons are)
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Off the top of my head, I'm going to say that it's not possible to mix and match %f (which supports a precision) and %g (which has a zero removal rule). You'd need to use a less direct solution, such as sprintf() followed by a right trim of zeros.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

*bushels[i] = *(bushels[i]*price);

The indexing operator already dereferences the pointer, what you're trying to do is dereference a float value, which clearly won't work. Try this instead:

bushels[i] = bushels[i] * price;

Or using the compound operator:

bushels[i] *= price;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wow, just...wow. See that word in your code that says readonly? Make it go away.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A readonly field `SearchEmp.name' cannot be assigned to

So...what does that tell you? It's not like the error is ambiguous or unclear. SearchEmp.name is defined as readonly, yet you try to assign to it as if it were not readonly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also please tell me about these error.

You forgot to list the errors, and your title for this thread is uninformative.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yup, it's pretty simple:

I didn't suggest otherwise. It's a smidge more complicated because we'd still want to support local avatars, but I'd almost call such a feature trivial to implement...almost. ;)

My concern had more to do with whether supporting Gravatar would be both sufficiently beneficial as well as likely to continue to be beneficial going forward.

cereal commented: agree :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For starters, movie_rent is neither an object nor an array, it's a type. The object declaration would be more correct like this:

struct {
    char name[20];
    char year[20];
    int inout[20];
} movie_rent[20];

But that doesn't fix your syntax issues because you can't seem to decide if movie_rent is an array and inout is an int (circa line 30 and 34):

movie_rent[i].inout=0;

...

fscanf(myfile,"%c %c %d[^\n]", movie_rent[i].name, movie_rent[i].year,movie_rent[i].inout );

Or movie_rent is a single structure instance and inout is an array of int (line 39):

sum=sum+movie_rent.inout[i];

I suspect you want an array of movies:

#include <stdio.h>

int main(void)
{
    struct rental {
        char name[20];
        int year;
        int inout;
    } movies[20];

    FILE *in = fopen("mov.txt", "r");

    if (in) {
        size_t i, n, sum = 0;

        for (n = 0; n < 20; n++) {
            if (fscanf(in, "%19s %d %d", movies[n].name, movies[n].year, movies[n].inout) != 3) {
                break;
            }
        }

        fclose(in);

        for (i = 0; i < n; i++) {
            sum += movies[i].inout;
        }

        printf("Available movie count: %d\n", sum);
    }

    return 0;
}

This should work for movies that have a single word name (it's untested, so I reserve the right to have made stupid errors/typos), but for multiword names you're SOL using the %s specifier and need to figure out something different. I'd suggest flipping the format around so that the name is last, then doing this:

if (fscanf(in, "%d %d %19[^\n]", movies[n].name, movies[n].year, movies[n].inout) != 3) {
    break;
}

That way you …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

they are all array notation but char** val is implicite and char* val[] is explicite

It's the other way around. They are all pointers, and the [] option is syntactic sugar to highlight the intention that the parameter is an array. But also note that this equivalence only applies to the first dimension of a the array notation. All subsequent dimensions require a size and represent array types. Consider this:

int main()
{
    int a[2][4];

    foo(a);
}

foo() must be declared in one of two ways:

void foo(int a[][4]);  /* First dimension decays into a pointer */
void foo(int (*a)[4]); /* Explicitly stating the first dimension as a pointer */

It's a common misconception that the double pointer type corresponds to a 2D array, which is false:

void foo(int **a); /* Fails to compile */
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As an avid avatar junkie, why would you want to have the same avatar on different forums? ;)

Just kidding, it's a nice idea. I'd actually never heard of Gravatar though, so I'd have to look into it. There's also the niggling worry about using plugins to off-site storage that may disappear in the future. It's fairly safe to say Facebook will be around a while (for our Facebook login), but having not even heard of Gravatar before there's a little doubt in my mind about its pervasiveness.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is char** val the same as char* val[ ]

Only as formal parameters in a function definition. Otherwise, they're not. I'm assuming we're talking about parameters for the answer to your next question.

when is the formal (char** val) used

I'll use the array notation when I'm absolutely sure that the function is intended to work with an array or simulated array. I prefer to use pointer notation when the object is known to not be an array or whether it's an array is unknown.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your best bet is to try running Mono on the machine and hope for the best. However, there's a fairly strong likelihood that your code uses .NETisms not available in Mono and will require modification to port it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What API? Chances are good the answer to your question is yes, but it's a little vague.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does it make a functional difference or is it just a formatting preference?

It's a formatting preference, assuming I understand your question. C# inherits a C rule wherein if you don't include braces on a compound statement (eg. if, while, or using), the next statement constitutes the body. So you can chain usings like you did:

using (TcpClient clientSocket = new TcpClient(host, port))
    using (NetworkStream clientStream = clientSocket.GetStream())
        using (StreamWriter toOmega = new StreamWriter(clientStream))
            using (StreamReader fromOmega = new StreamReader(clientStream))
            {
                ...
            }

And the functionality is as if you did this:

using (TcpClient clientSocket = new TcpClient(host, port))
{
    using (NetworkStream clientStream = clientSocket.GetStream())
    {
        using (StreamWriter toOmega = new StreamWriter(clientStream))
        {
            using (StreamReader fromOmega = new StreamReader(clientStream))
            {
                ...
            }
        }
    }
}

Because the braces aren't needed for all but the innermost statement (unless its body only consists of a single statement), you'll often see an unindented chain because it tends to look cleaner than the unbraced indented version:

using (TcpClient clientSocket = new TcpClient(host, port))
using (NetworkStream clientStream = clientSocket.GetStream())
using (StreamWriter toOmega = new StreamWriter(clientStream))
using (StreamReader fromOmega = new StreamReader(clientStream))
{
    ...
}

But some people (myself included) feel that this obscures the structure of the code, and prefer the fully braced and indented version.

do the repsonses pile up in a buffer that can be read sequentially like this?

Yes. You might consider using WriteLine() instead of Write() though, so that ReadLine() finds …

Ketsuekiame commented: Unfortunately straight line compound is becoming more popular in the junior devs we get here :( +8
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You only allocated memory for p4. p3, p2, and p1 are all still uninitialized.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, the ArtWork folder exist at that location ("...bin\debug\Artwork") ;

That's not the location referenced by your error.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

deceptikon: A dispose method should be coded so that it cannot throw an exception, or, if it does, bin out of the application

My comment wasn't about exceptions thrown from within Dispose(). My concern was more general in that all of your calls to Dispose() may not happen if intervening code throws. For example:

bar.Dispose();
Console.WriteLine("bar disposed");
foo.Dispose();
Console.WriteLine("foo disposed");

If the first WriteLine() throws, foo.Dispose() won't execute. A using statement fixes this

using (var foo = MakeFoo())
{
    using (var bar = MakeBar())
    {
        // Stuff that can throw
    }

    Console.WriteLine("bar disposed");

    // Stuff that can throw
}

Console.WriteLine("foo disposed");

by forcing all of the necessary Dispose() calls to execute in a finally statement:

{
    var foo = MakeFoo();

    try
    {
        var bar = MakeBar;

        try
        {
            // Stuff that can throw
        }
        finally
        {
            if (bar != null)
                bar.Dispose();
        }

        Console.WriteLine("bar disposed");
    }
    finally
    {
        if (foo != null)
            foo.Dispose();
    }

    Console.WriteLine("foo disposed");
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Or should I do this (seems overkill):

You should do that. It may seem like overkill to you now, but a using statement (implicitly calls Dispose()) will flush the streams, close them, and dispose of any internally allocated resources. To do it manually would require calling Dispose() manually, which could cause problems in the presence of exceptions.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, my gut reaction was correct. The operator<< signature should be this:

friend ostream& operator<<(ostream& out, GenericList<T> theList);

You'll get an unresolved external error until the function is defined, but the main issue was you were passing the wrong type.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but it creat error in the above line "<<list1"

Are we supposed to telepathically extract the error from your mind?

friend ostream& operator<<(ostream& out, T theList);

This looks odd (T here should be the type of the class), but I'm not confident saying for sure since you provided so little code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does the ArtWork folder exist at that location?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

deceptikon, your method compiled just fine but didn't actually change the output of the number. If I entered 12345 it would still out put 12345 rather than 012345 which is what I'M trying to get.

Let's make something abundantly clear: the type of string matters. Are you using a C++ string object? In that case, my solution works:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s = "12345";

    s = '0' + s;

    cout << "'" << s << "'" << '\n';
}

If you're using a C-style string, which is nothing more than an array of char terminated by '\0', it's less intuitive, more awkward, and easier to get wrong:

#include <cstring>
#include <iostream>

using namespace std;

int main()
{
    char s[10] = "12345";

    // Shift everything to the right by 1 to make room at the front
    memmove(s + 1, s, strlen(s) + 1);

    // Prepend '0'
    s[0] = '0';

    cout << "'" << s << "'" << '\n';
}
tux4life commented: From all suggested approaches I like these the most. +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

yeah but i have very short time to submit it so i ask like that :)

Last I checked, that wasn't a viable excuse for cheating. Please read our rules. When posting homework questions, we require proof of effort before you'll be offered any help. So even though you're short on time, you've already wasted quite a bit by not following proper procedure on Daniweb.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's wrong here:

while(temp!=NULL){[...]}
temp=add;

If temp is NULL after the loop then it no longer refers to the tree in any way. So assigning add to temp will accomplish absolutely nothing when insert() returns.

This was actually a stumbling block for me when I first started learning referential data structures. A null pointer isn't a part of the structure, and as soon as you set your reference into the data structure to null, you're done with it. To insert a node where a null currently resides, you must have a reference to the previous node:

while (true) {
    if (temp->item >= add->item) {
        if (temp->left == NULL)
            break;

        temp = temp->left;
    }
    else {
        if (temp->right == NULL)
            break;

        temp = temp->right;
    }
}

if (temp->item >= add->item)
    temp->left = add;
else
    temp->right = add;

There are a number of ways to do it, of course, but the above highlights the fact that as soon as temp becomes null, you're screwed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you tried:

s = '0' + s;

That's assuming you're using a std::string object. For C-style strings I'd recommend not using them because it makes just about everything harder.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon does strlen() function give the length of string in O(n) or O(1)?

You really can't assume that it's better than O(n), and it would take quite an idiotic programmer to make it worse than O(n). ;) The structure of C-style strings isn't conducive for optimizations that would improve the complexity because in the end you're searching for a character in the string. The library doesn't have control over when or where that character is placed, or even if it exists at all.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@moschops i am trying to avoid that loop. thats why i am using memset which fails.

What do you think memset() does? Internally it's just a loop. There might be some unrolling involved or it might be written in assembly to speed things up, but it's still a loop.

Here is a conforming (and portable) implementation of memset(). You'll notice there's not much to it, and it matches the spirit of Moschops' example.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How can I calculate CLOCKS_PER_SEC.. It is defined as 1000 in ctime. I don't want it defined. I want to calculate the actual value..

CLOCKS_PER_SEC is a standard macro, you can ignore it if you'd like, but you shouldn't redefine it.

So what is CLOCKS_PER_SEC and why is it defined as 1000? How can I calculate it?

CLOCKS_PER_SEC is the number of units calculated by std::clock() over the span of one second. std::clock() is defined as such:

"The clock function returns the implementation’s best approximation to the processor
time used by the program since the beginning of an implementation-defined era related
only to the program invocation."

As a concrete example, one of my simple C standard libraries implements clock() as this:

/*
    @description:
        Determines the processor time used.
*/
clock_t clock(void)
{
    return _sys_getticks() - __clock_base;
}

Where __clock_base is a static object initialized to _sys_getticks() at program startup, and _sys_getticks() is defined like so:

/*
    @description:
        Retrieves the process' startup time in clock ticks.
*/
long long _sys_getticks(void)
{
    return GetTickCount64();
}

GetTickCount64() is a Win32 API function that returns the number of elapsed milliseconds since system startup, which means for this implementation clock() returns milliseconds since program startup, and CLOCKS_PER_SEC is the number of milliseconds in a second (ie. 1000).

I'm trying to run a function every actual tick.

Define "tick". Apparently the tick of std::clock() isn't sufficient, and neither is the …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I suspect that semicolon at the end has something to do with it not doing what you want:

#include <iostream>

int main()
{
    int year = 1985;

    if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
        std::cout << "Leap year\n";
    else
        std::cout << "Not a leap year\n";
}

I gave you a complete function, there was no need to change it. Especially since by changing it you apparently broke it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thinking about it, I'm unsure why anyone would give a student such a task, how could you ever have a c-style array you do not know the size of anyway?

I suspect one of two things:

  1. The OP simply misinterpreted the problem requirements (most likely).
  2. The problem requirements are wrong for some reason.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In lines 75-79, you unconditionally delete the head if it's the only node in the list. What if id != head->st.id in that case? As for successfully deleting the first node when it matches the id, consider adding another clause between lines 79 and 80 that handles a true deletion of a matching head:

else if (id == head->st.id)
{
    tmp = head;
    head = head->link;
    delete tmp;
}

This will reseat the head to the 2nd node in the list, and then release memory for the old head.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't have a solution, but I do know it would be complicated

If you don't know of a solution, how do you know it would be complicated? ;)

I've learnt never to assume something is impossible in the land of programming.

That's not a bad thing, though in this case it is indeed impossible without introducing assumptions about the contents of the array or relying on non-portable solutions. Note that I'm making the same hedge about the unknown here. While I'm not aware of a platform-specific hack that would give you the size of an array through a pointer to its first element, I can't confidently say that no such solution exists.

while (v[i] < 2147483648 && v[i] > -2147483647)

I suspect you believe that this loop works because 2147483648 is overflowing a signed int and wrapping around to INT_MIN on your implementation. When I test the code on Visual Studio 2012 (Windows 7), v[5] is -858993460. The maximum value for signed int is 2147483647 as well, and by saying 2147483648 the behavior on this implementation is to wrap to -2147483648, which is certainly less than -858993460. Thus the loop terminates with the correct result, but certainly not because it's working as intended.

You can break the code by making any value in the array negative.

A more portable loop would be:

while (v[i] < INT_MAX && v[i] > INT_MIN)

But then the bug that caused it to appear to work …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But I think it happens even to more experienced people, don't you agree?

Yup, though more experienced people tend to welcome others pointing out such mistakes.

On the other hand, interesting enough that you felt like giving me a lesson instead of simply posting the correct way.

I didn't give you a lesson, I pointed out that your code suggested a distinct lack in your understanding of leap years. Thus I recommended you do some more research. And you'll notice that I did post the correct way, though it was in response to the OP rather than you.

I wonder if it is related to my answers to you by now.

I won't deny that the likelihood of someone responding in an entertaining way affects how I choose to phrase my posts. :D

Hmm... I am wondering what you refer to here? That's because I have no idea what you meant there.

I meant that you made an unwarranted assumption (some might even call it stupid) and gave a common example of another assumption that's equally annoying.

Nevertheless, this conversation gets way out of the subject, don't you think?

The question has been answered. We won't know if the OP needs more help until/if he replies.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Note that this works fine for char, because char is 1 byte (the size of each element of the array if you will).
If the type were int for example, you need to do a bit of testing forinstance
check that the size of the array is divisible by the type of the array, so as not to exceed its bounds.

I don't understand the point you're trying to make. If you change char to int in your code example, it will still work perfectly:

int arrayX(int * a, int lookfor, int size){
    int found = 0;

    for (int i = 0; i < size; i++){

        if (a[i] == lookfor){

            found++;
        }
    }

    return found;
}

int main()
{
    int a[10] = {'a','b','z','c','z','e','f','g','z','z'};

    cout << arrayX(a,'z',10) << endl;

    return 0;
}

Did you mean only changing lookfor to int and leaving a as a pointer to char?

If you do not know the size of the array, then iy will become much more complicated, but I would not say impossible.

Please describe this "more complicated" solution of finding the size of an array when given nothing but a pointer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Big words for an admin, don't you think?

As an admin I have to show that I'm a step above the average semiliterate web denizen. I'm sorry if I made you look up any words to figure out what I was saying. ;)

Relax, it was only a joke which wanted to say that I am not working in my calendars with dates so far as year 1900 and I don't expect any of my applications to live for 87 years from now.

I figured that was the case, but it's irrelevant what you need the formula for, and the joke wasn't obvious from your code. If you're posting code as help for someone else, you can't assume that their needs match your needs, especially when your needs are a teeny tiny subset of possible applications.

It's no different than when someone posts code that only compiles under Turbo C++ with the implicit assumption that everyone else uses that compiler. Someone will call you on it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your findMin() has two problems, one is a bug and another is a usability problem. The bug is that you're moving the pointer ahead by j steps on every recursive call, but you're also using j as an index into the array. This is basically a guaranteed access out of bounds. Either use j to access the array, or move the pointer ahead by 1 each time:

/* Option 1: Use a static index */
int findMin(int *arr, int min, int size)
{
    printf("in findMin() : passed values >> array:%d  min:%d  size:%d\n", *(arr), min, size);

    static int j = 1;

    if (j == size){
        return min; 
    }
    else if (min > arr[j]){
        min = arr[j++];
        return findMin(arr, min, size);  
    }
    else {
        j++;
        return findMin(arr, min, size);
    }
}

/* Option 2: Adjust the pointer */
int findMin(int *arr, int min, int size)
{
    printf("in findMin() : passed values >> array:%d  min:%d  size:%d\n", *(arr), min, size);

    if (size == 0)
        return min; 

    if (min > *arr)
        min = *arr;

    return findMin(arr + 1, min, size - 1);
}

The second option is recommended because using a static variable makes your function non-reentrant. In other words, you can only find the minimum element of an array one time. Any subsequent calls will continue to increment the index. That issue with the static variable is your usability problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the simplest way to do this?

It's not a matter of simple or not, it's a matter of possible or not. If you're not given a size, can't assume a size, and there's no sentinel value marking the end of the array then you're shit out of luck. In the general case, it's simply not possible to determine the size of an array when all you have is a pointer to the first element.

You seem to be missing key information to solve this problem, such as how is the array set up? Are the items in random order or are they sorted somehow? Is there a sentinel value marking the end? You should probably go back to the person who gave you the assignment and ask for details.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I still have time until 2100 when my formula will blow up. And, definitely, I am not that old to know how was in 1900. ;)

No offense, but that's the most asinine thing I've read all day.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Now that I've converted the formula over to C++ it's not working out.

It's the wrong formula. This is correct:

bool is_leap_year(int year)
{
     return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

if ( year % 4 == 0 ) return true;

You might want to read up on leap years.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

With three programming courses under my belt will I be able to find a job out there in the real world?

Getting a programming job has less to do with how much you know about programming and more to do with selling yourself. So while I'd say that right now, from the given information, I wouldn't hire you, it doesn't mean you can't find a job.

Do you have any recommendations on courses that I should take?

Apparently you want to be a Java developer, so take any courses you can.

Do you recommend that I take the Java Certification exam after I finish my advanced Java course?

Yes.

My school offers Enterprise Java, should I take it?

Probably, yes.

Do you believe that I can find a programming job right now?

I think you'll find it extremely difficult. Consider joining some open source projects to build experience. You can also use your existing business contacts to get an edge on folks who are just sending in resumes or walking in the door without knowing someone in the company.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My problem is after change the value of Masked raider the jimmy changed,but when set jimmy = "not ok";
Masked raider did not change,how to explain it?

When you changed jimmy to "not ok", you pointed it to a different object (the string literal "not ok"). At that point, jimmy no longer aliases masked_raider.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That means the size of the array is unknown.

That means you shouldn't be using an array. Use a List<> instead, unless this is a homework assignment where the whole point is to learn how to work with arrays. Though such an assignment seems silly since the Array class has supported a Resize() method since .NET 3.5.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can do a simple replace on the string:

textBox.Text = textBox.Text.Replace("Yes", "NO")

Changing the color is a different matter. I assume you want to change only the replaced text to red, which won't work unless you're using a rich text box. If it's just a regular text box then you're limited to a global foreground color change. But that can be done by changing the ForeColor property:

textBox.ForeColor = Color.Red

For a rich text box it's a bit more complicated, but you can search for substrings with that control, select them, and then set the color for the selection to red. See the documentation for details.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, you're probably screwed. Consider using source code version control in the future. As a last ditch effort, you can check your autorecovery backup files for the project. It depends on your OS, but the folder is under your documents. For example, on my Windows 7 machine it's:

C:\Users\jdaughtry\Documents\Visual Studio 2010\Backup Files

I wouldn't get your hopes up if I were you though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but kept getting an error

It's never a bad idea to post the error.