deceptikon 1,790 Code Sniper Team Colleague Featured Poster

u showed the use of fflush(stdout). a bit confusion here, coz i read in this page that using fflush is a bad thing. although they only mentioned it for the case of fflush(stdin).

Kudos for critical thinking and an eye for detail. :) The difference between good and bad with fflush() is indeed in the argument. fflush() is defined only for output streams or update streams presently in an output orientation. It's not designed for input streams, and technically, passing an input stream or update stream in input orientation to fflush() invokes undefined behavior.

So fflush(stdout) is fine and dandy while fflush(stdin) is undefined behavior.

Note that the two are totally different in expectations as well. When someone uses fflush(stdin), they typically expect the functionality to be akin to this:

if (the stream contains characters)
{
    /* Extract and discard excess characters */
    int ch;

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

The "if the stream contains characters" part is not possible without delving into non-portable options. But the concept of "flushing" an input stream is usually reading and throwing away characters until the stream is empty.

fflush(stdout) on the other hand is all about writing unwritten characters. If you send a prompt to the screen, flushing stdout will force that prompt to be displayed immediately. If you're writing to a file, flushing the file stream will force any buffered characters to be written to the file. This is …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hi, can anyone please explain why i am getting output as "ishq" even if i=0.3 so if condition must be false. pleas help i am not getting it.

What Every Computer Scientist Should Know About Floating-Point Arithmetic

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon..then why dont the first code is working without allocating the memory?

The pointer is being assigned the address of an existing array.

my basic ques is do we need to allocate memory to a pointer before using it?

You need to ensure that the pointer points to memory that you own.

i mean in my first code why dont we malloc 'b' before the (b=a) statement?

Because that's unnecessary and would cause a memory leak. The b = a statement is sufficient to meet the requirement of pointing to memory that you own.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What compiler are you using?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So, in the float case statement, it will give unexpected o/p? Reason : I am using int (age) at that time. right ? for making this correct also, i should write

e1.salary=101.45f;
or something like that and then use printf statement for this. am i right ?

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Make an array with every exercise and randomly pick one?

Yup. Though for a workout generator you probably don't want to pick the same exercise twice, so a random shuffle may be more appropriate.

How would I go about doing that?

Here's an example:

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

#define length(x) sizeof (x) / sizeof *(x)

static const char* data[] =
{
    "test 1",
    "test 2",
    "test 3",
    "test 4",
    "test 5"
};

int main(void)
{
    int indices[length(data)];
    int i;

    /* Initialize the indices */
    for (i = 0; i < length(data); ++i)
    {
        indices[i] = i;
    }

    /* Randomly shuffle the indices */
    for (i = 0; i < length(data) - 1; ++i)
    {
        int r = i + (rand() % length(data) + 1);
        int temp = indices[i];
        indices[i] = indices[r];
        indices[r] = temp;
    }

    /* Select a portion of the shuffled array */
    for (i = 0; i < length(data); ++i)
    {
        printf("%s\n", data[indices[i]]);
    }

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

The #define directive is a glorified cut and paste. You can see why that macro is wrong by doing the cut and paste manually:

if(a=='A','B','C','D','E','F','0','1','2','3','4','5','6','7','8','9')
    printf("hexadecimal");

Well, you may not see it because this is a common confusion point for beginners to C. You don't compare a variable to a list directly like this, you must compare the variable to each individual item. So to compare against 'A', 'B', 'C', 'D' (because it's shorter for this example), you'd do this:

if (a == 'A' || a == 'B' || a == 'C' || a == 'D')
    printf("A, B, C, or D\n");

Obviously that's tedious, so a better solution is to store the "list" of matches in an array and then loop over the array while doing that comparison:

#include<stdio.h>

int main(void)
{
    char const hex[] = "0123456789ABCDEF";
    char ch;

    printf("Enter a character: ");
    fflush(stdout);

    if (scanf("%c", &ch) == 1)
    {
        int i;

        for (i = 0; hex[i] != '\0'; ++i)
        {
            if (ch == hex[i])
            {
                printf("Hexadecimal\n");
                break;
            }
        }
    }

    return 0;   
}

The take-away lesson is that C doesn't do jack for you and there's very little "magic". You have to do everything explicitly, or use a library to do it for you explicitly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I only glanced over your post, but I'm 99.9% sure that it's the classic stream garbage problem when mixing formatted and unformatted input.

You see scanf() is special in that most of the time it will discard leading whitespace from the stream and leave trailing whitespace. gets() on the other hand, doesn't discard leading whitespace and will stop reading when it encounters a newline. So what happens when you use scanf() followed by gets() when scanf() leaves a newline in the stream?

You guessed it: it appears that gets() is skipped because it terminates successfully on the first character, the newline. The following program exhibits the problem clearly:

#include <stdio.h>

int main(void)
{
    char s[BUFSIZ];
    int d;

    printf("Enter a number: ");
    fflush(stdout);

    while (scanf("%d", &d) == 1)
    {
        printf("You entered %d. Enter your name: ", d);
        fflush(stdout);

        if (fgets(s, sizeof s, stdin))
        {
            printf("You entered '%s'\n", s);
        }

        printf("Enter a number: ");
        fflush(stdout);
    }

    return 0;
}

There are two common fixes:

  1. Don't use scanf(). Always use some variant of fgets() to read lines from the stream and then parse them using sscanf(). This way the stream is always kept pristine for fgets().

    #include <stdio.h>
    
    int main(void)
    {
        char s[BUFSIZ];
        int d;
    
        printf("Enter a number: ");
        fflush(stdout);
    
        /* Note that s is being reused here as the temporary line for d */
        while (fgets(s, sizeof s, stdin) && sscanf(s, "%d", &d) == 1)
        {
            printf("You entered %d. Enter your name: ", d);
            fflush(stdout);
    
            if (fgets(s, sizeof s, …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Will you please tell how many and which one statements are wrong in the code I have given ?

  • The code doesn't include <stdio.h>, which is technically OK except in the case of functions with variable length argument lists like printf(), where the behavior is undefined. Either way, best practice is to include the headers you need.

  • <string.h> isn't included either.

  • char name[]; is illegal because the array doesn't have a size. If it happens to compile, it's because of a compiler extension. In C99 the "struct hack" has been blessed as flexible array members. However, the member must be the last one in the structure, and the feature is questionable in writing robust code. Further, if I recall correctly that feature doesn't apply to unions.

  • const union emp e1; is exceptionally stupid, in my opinion. Of course there's the obvious problem of not initializing the union, but there's also the conceptual issue of a const union being nonsensical in the first place.

  • strcpy(e1.name,"H"); won't work because e1 is const, obviously.

  • e1.age=45; won't work because e1 is const, also obviously.

  • printf("%f\n",e1.salary); is unspecified behavior because you're requesting the value of a different member than the one previously stored (.age, in this case). Will it work? Probably, but it's not strictly required to do what you expect, and you'll need to consult your compiler's documentation to find out exactly what does happen.

    I can't confidently say that it's undefined behavior without consulting the C standard (though I'm reasonably sure), …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For what purpose would you want a constant union? Anyway, you can initialize a union to the first listed member prior to C99, and you can use a designated initializer for an arbitrary member in C99 and later.

/* Earlier than C99 */
const union emp e1 = { "doodage" };

/* After C99 */
const union emp e1 = { .age = 45 };

But once again I'd question why you're declaring a union to be const when the entire point of unions is reuse of a single block of memory for multiple members when those members aren't needed simultaneously.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I already learnt linked list, trees and all.

Clearly you haven't realized how many variations of the above there are. Do you know intimately all of the tree variations listed here? That's just a teeny tiny helping of tree variations and enough to take up a few months of your learning time. You can find a rather huge list of algorithms and data structures that is fairly regularly updated here.

If you do it thoroughly, you could spend years learning about nothing more than tree data structures. So I'm skeptical when anyone says they're "done" learning something so deep and broad as a category of data structures.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the problem? Barring a minor semantic error (failure to return something from menu()) the program seems to work properly with a few simple test numbers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but here i require to allocate memory to b. why is so?

Where did you think the memory would come from? Pointers don't magically point to infinite memory on declaration, you have to point them to a block of memory that's allocated for that purpose, either through dynamic allocation (malloc and friends) or by assigning the address of an existing object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

HI everyone ,In this semester i have a course on data structure , My teacher is going to recomend us C# or C++ for implementing structures . i have good skills on c language and java but dont know C# and i hate c++(however i have learnt some bit of c++),plz tell me whether java or c will work fine and efficiently or i should learn c++? Thnx for your wisdom words.

If your teacher only allows C# or C++ then it's irrelevant how "fine" or "efficiently" Java or C will work. You need to verify that those languages are allowed first. But yes, you can use any of the four stated languages for implementing data structures.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If I write a C++ program and compile it into an executable file AND, don't have to install the program, will I have trouble running that C++ written program on other platforms?

Yes, you probably will. The executable itself is specific to the operating system and chipset where you built it. For example, if you try to run a Windows executable on Linux without an emulation layer like Wine, it'll fail.

Portability at the code level is about compilation, not execution. If your code is 100% portable, you should be able to rebuild it on any platform with a compiler and not encounter errors. There are also degrees of portability; it's difficult to write a completely portable program, but you can make porting the code easier by segregating the non-portable parts.

At a higher level you have things like byte code portability (a la Java) where the code is compiled into an intermediate byte code that's subsequently run by a virtual machine. The compiled byte code can be executed on any platform that supports the virtual machine, and the end result is close to full executable portability.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so this tells me that it doesn't refer to first element of array or I should say that it is not giving us address of first element of array , rather giving us address of an array of a particular size ? am i right ?

This is where people often get confused. The address of the array is the same as the address of the first element. The difference between a pointer to an array and a pointer to the first element is how that address is interpreted through the data type.

Later down the road you can use this concept to your advantage through a technique called type punning.

So this means these statement will give wrong result

It's not that it won't work as expect, but that's a possibility. Passing a type that's unexpected to scanf() or printf() will invoke undefined behavior. At that point, anything at all could happen, which includes working as expected.

My biggest issue in the past with correcting this error has been the "it works for me" logical fallacy. I'll say that the code is buggy, and the author will respond with "but it works for me".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

printf ("The value is %d and the address is %p\n", x, & x);

Another minor point, but to be strictly correct you must to cast the argument for %p to void* because that's the type printf() expects:

printf("The value is %d and the address is %p\n", x, (void*)&x);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let's start with the design of the class.

timer aTimer;
aTimer.Start();

This is kind of an equivalent design issue, but in many cases one would want the timer to start immediately without having to explicitly call Start(). Perhaps a constructor parameter that tells it to start or not?

while( aTimer.GetTicks() < 1000 );

I have a beef with your choice of the name GetTicks() because it exposes the implementation and also goes against your claim that this timer works in intervals of milliseconds. If you're guaranteeing millisecond resolution, then call it Milliseconds() or simply Elapsed().

Another unnecessary exposure of the implementation is the return type of clock_t.

You provide a Start(), Stop(), Pause(), Resume(), and Reset(), but Elapsed() is only effective when the timer is running. The interface itself implies different behavior than is actually offered. Elapsed() in this case should return the result of the previous or current bout of timing (depending on whether the timer is running or not), in my opinion.

I think the interface is too complicated, actually. Still using the clock_t implementation (which I don't agree with in principle), something simpler and more dummy-proof would be better for a what essentially constitutes a stopwatch. In fact, stopwatch is a better name for the class. ;)

Consider the following:

#include <ctime>

class Stopwatch
{
public:
    explicit Stopwatch(bool start_immediately = false);

    void Start(bool reset = false);
    void Stop();

    unsigned long Elapsed() const;
private:
    std::clock_t start, stop;
    bool running;
};

Stopwatch::Stopwatch(bool start_immediately)
    : …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your 1st loop 2nd loop terminology is almost unintelligible, but the only other interpretation I can think of is clearly and completely answered in this sticky.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

means code written above will not work ? because sizeof will not work as you have said ?

It will work, but only because the function parameter is a pointer to an array.

here p is a pointer to an array. so sizeof(*p) is size of complete array ? is this right ?

Yes, that's it exactly.

Will you please tell that when we say &a, then isn't it refer to first element of array ? it is a question in one book. i am not getting it.

This is where people tend to get confuzzled. The address is the same, but the type is different. So for int a[5];, a gives you a pointer to int and &a[0] also gives you a pointer to int, because both of these are value context expressions on the array. &a is an object context expression on the array, so the result, even though you get exactly the same address, has a different type: int(*)[5].

Note that this is why the following call to scanf() is buggy:

char name[50];
scanf("%49s", &name); /* The ampersand shouldn't be there! */

The reason why it's buggy is because scanf() is being passed a pointer to an unexpected type. scanf() expects char*, but what's actually passed is char(*)[50].

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When you open a stream and then read to the end, it doesn't magically reset to the beginning at the programmer's convenience. In fact, it stays right where you last stopped reading. You need to clear the error state (because it will be marked as end-of-file) and reset the get pointer to the beginning any time you want to start reading the file from the beginning:

infile.clear();
infile.seekg(0, ios::beg);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

one last point i wana ask which is generated from this explanitaion only.
will you please this line again ? "As an operation to the address-of (&) operator. When you say &a, you get a pointer to an array, not a pointer to a pointer to the first element. If this expression were evaluated in value context, it would be impossible to create a pointer to an array, which would be problematic as that's the type of nested dimensions in a multidimensional array."

I suspect you haven't yet encountered pointers to arrays in their explicit form:

#include <stdio.h>

void foo(int (*p)[5])
{
    /* 
        Note that sizeof won't work here without a pointer to an array
        because we need the size of the whole array object, not just a pointer.
    */
    for (int i = 0; i < sizeof *p / sizeof **p; i++)
    {
        printf("%d ", (*p)[i]);
    }

    putchar('\n');
}

int main(void)
{
    int a[] = {1, 2, 3, 4, 5};
    int (*pa)[5] = &a;

    foo(pa);

    return 0;
}

You can also probably guess why they're not often used: the syntax for declaring and dereferencing a pointer to an array is...awkward.

But I think the part of my explanation that was troubling is mention of pointers to arrays as nested dimensions in a multidimensional array. That was wrong, and I have no excuse. What I intended to write (how it came out the way it did is beyond me) is that a pointer to an …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In this article we try to abuse the preprocessor so much that C++ no longer looks like C++.

#include <iostream>

#define also ,
#define stop ;
#define begin {
#define end }
#define args(x) (x)
#define scalar int
#define letter char
#define ref(x) x*
#define seq(x, n) x[n]
#define start main
#define print std::cout <<
#define nl << std::endl
#define from(x) = x;
#define to(x) i < x; i++)
#define repeat_with(x) for (int x
#define index(a, i) a[i]

scalar start args(scalar count also ref(letter) seq(args,))
begin
    repeat_with(i) from(0) to(count)
    begin
        print index(args, i) nl stop
    end
end
NathanOliver commented: My boss would kill me if he saw this +9
major_tom3 commented: The finest bit of satire I have seen on a C++ thread. Made my day! +0
Satyrn commented: ahh crafty. I love this idea but I would hate reviewing code that did this ><. This isn't Python! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Or seeing as PHP will already parse the entire string because you're using double quotes, you could avoid string contatenation and just include the parameter directly in the string

Indeed. Though I chose concatenation because interpolation doesn't stand out as much for this particular string (ie. it's relatively long and noisy). Barring an editor that highlights interpolated variables, I'd prefer the more verbose concatenation for purposes of transparency.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
$table1 = 
    "<div id=\"container\"><table id=\"table-3\" cellspacing=\"0\"><thead><tr><th>Totalt</th><th>" .
    $Totalt .
    "</th><th>Benchmark</th><th>Differans</th></tr></thead><tbody>";
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How are you storing the graph? That kind of matters in the implementation. ;) Another critical factor would be whether there's a cycle in the graph or not. It's simpler if you don't have to consider revisiting a node.

In fact, if there are no cycles then you can probably store the graph as a tree and call it good with a simple preorder traversal:

#include <iostream>
#include <vector>

using namespace std;

struct node
{
    char value;
    vector<node*> link;
};

void PreOrder(node* root)
{
    cout << root->value << ' ';

    for (vector<node*>::size_type i = 0; i < root->link.size(); ++i)
    {
        PreOrder(root->link[i]);
    }
}

int main(void)
{
    node tree[9];

    // Initialize to the stated graph
    tree[0].value = 'A'; tree[0].link.push_back(&tree[1]);
    tree[1].value = 'B'; tree[1].link.push_back(&tree[2]);
    tree[2].value = 'C'; tree[2].link.push_back(&tree[3]); tree[2].link.push_back(&tree[4]);
    tree[3].value = 'D'; tree[3].link.push_back(&tree[5]);
    tree[4].value = 'F'; tree[4].link.push_back(&tree[6]); tree[4].link.push_back(&tree[7]);
    tree[5].value = 'E';
    tree[6].value = 'I';
    tree[7].value = 'G'; tree[7].link.push_back(&tree[8]);
    tree[8].value = 'H';

    // Do a straight inorder traversal to display
    PreOrder(tree);

    return 0;
}

The only trick from there would be saving the current path at each node, which constitutes most of the effort of this solution after making the connection between your graph and a multi-way tree where a preorder traversal accomplishes the goal of pathfinding.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

One last thing,do we need to learn any other subjects to develop a software other than just the programming language..??

Yes, you need to learn general programming theory and problem solving. The rules of the language are easy to learn, putting them together into a functional, robust, and useful piece of software is much more difficult.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon will you please write it in again into more simpler form ?

It really depends on what you want the code to do, but if you're trying to display the contents of the 2D array with pointer notation, you don't even need an intermediate pointer variable:

#include <stdio.h>

int main(void)
{
    /* This is better because it highlights the structure of the array more clearly */
    int a[][2] =
    {
        {1, 2},
        {3, 4}
    };
    int i, j;

    /* At the very least, use braces around the outer loops */
    for (i = 0; i < 2; i++)
    {
        for (j = 0; j < 2; j++)
        {
            /* Note how the pointer notation still works with an array variable. */
            printf("%d ", *(*(a + i) + j));
        }
    }

    /* This makes output cleaner for the next program */
    putchar('\n');

    return 0;
}

@sepp2k will you please tell me what "decays" means ? I have read it at more than 20 places. but I never get it's meaning. if any body asks me a[] is an array or pointer or both ? then what should i say to him/her ? please elaborate!

"Decays" is used because pointers are seen as lower level entities from arrays. What really happens is an array variable name, when used in value context, will be converted to a pointer to the first element of the array. Thus the following two printf() calls are functionally identical:

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

And i want to ask that in p[] definition, why it is written (int) with every element since a is already an pointer.

It's already a pointer, but the type is different. Try removing the cast and you'll get an error similar to: "type mismatch between int(*)[2] and int*"

The fact that the cast hides an error should give you pause when writing code like this, because it suggests that you're doing something stupid. In particular, it's not safe to assume that you can pun a 2D array into a 1D array using a pointer because there's potential padding at the end of each 1D array in a 2D array that could produce trap representations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

size_t //Eerm, what is size_t?

It's a typedef for an undisclosed unsigned integer type (usually int or long). It's defined in <cstddef> along with a number of other C-inherited headers, and the intended usage is as the result type of the sizeof operator.

Since sizeof is often used to calculate the number of elements in an array, it also makes sense to use size_t as the index variable type.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I came across this program in the C++ section. How to do something similar in C?

While that program is indeed written in C++, the conversion to C is trivial as the overall structure doesn't depend on anything specific to C++. The library being used is Windows' Win32 API.

I see only a few minor things that need to be changed (there may be multiple instances of each):

  1. Variable declarations mixed with statements may not be legal in your version of C. Declare all variables at the start of a block.

  2. The bool type may not be available in your version of C (if it is, include <stdbool.h>). You can replace it with int, and true/false with 1 and 0.

  3. Replace <iostream> with <stdio.h>.

  4. Remove using namespace std;

  5. Either remove cin.ignore(); or replace it with getchar();.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If by "help" you mean "do it for me" then no. If you want actual assistance rather than a hand out, then please ask a specific question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Strings are not arrays so they dont end in \0 right? So how would i check if there is anything in the string at all?

There are a number of options, but if you want to say what you mean then this one stands out:

string s;

if (getline(cin, s))
{
    // Check for emptiness
    if (s.empty())
    {
        cout << "Empty!" << endl;
    }
    else
    {
        cout << "You typed '" << s << "'" << endl;
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is it airline reservation homework time of year already? Oh, how the year flew by. :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can't use the == operator to compare arrays. Well, you can, but it almost certainly doesn't do what you expect or want.

Ideally you'd use a std::string object instead of an array of char for strings, because then the == operator is overloaded and does what you want. Otherwise, you're stuck with the C-style method of calling strcmp():

#include <cstring> // Include this guy for strcmp()

...

if(strcmp(_cFileName, "HELP") == 0)
{
    // The user typed "HELP"
}

Now the user typing nothing is a bit harder because nothing will be written to the string. You must initialize the array to an empty string, and then you can compare the first character against the string termination character to see if nothing was written:

_cFileName[0] = '\0'; // Clear the string

...

if (_cFileName[0] == '\0')
{
    // The user typed nothing
}

On a side note, the system() function is declared in <cstdlib>, which you neglected to include. This is an error that your compiler probably overlooked, but you shouldn't rely on that behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How can I know my logic skills are good enough for programming?

Can you methodically work toward an understanding of a problem and devise a solution using common sense? If so, your logic skills are good enough.

Is it something you either have or you don’t; or do they come with practice?

It's definitely about practice. Some people have an innate talent for problem solving, but that just gives them a head start. Programming and problem solving are learned skills; you'll get better at them with experience, and no reasonable employer will expect you to be a rock star right out of university.

Is it true that employers are biased towards employing younger developers (in their 20s and 30s)? (I will be about 40 when/if I graduate:o))

Age discrimination is illegal in the UK.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hi deceptikon, what is the content of input file (in your case test.txt). It is nowhere mentioned.

I used a super duper secret and obscure test case for the content of the file:

1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24

;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It compiles and runs up until the first function is called then crashes

I'm surprised it compiles. What compiler are you using? Anyway, there are a number of problems with your code such that it would be faster to give you a good example instead of enumerate the existing issues.

So here is a program that reads numbers into a 2D array, multiplies them by a user provided multiplier, and saves the result to a file with optional echo to the standard output. Please ask questions as I'm sure you'll have at least one. Note that I've taken care to comment interesting or important things in anticipation of questions you might not be in a position yet to ask:

#include <stdio.h>
#include <stdlib.h> /* For EXIT_SUCCESS and EXIT_FAILURE */

#define ROWS 4
#define COLS 6

int FileLoad(FILE* in, double a[ROWS][COLS], int stdout_echo);
void FileSave(FILE* out, double a[ROWS][COLS], int stdout_echo);
void Multiply(double a[ROWS][COLS], double multiplier);
void FlushLine(FILE* in);

int main(void)
{
    FILE* fp = fopen("test.txt", "r+");
    double a[ROWS][COLS];
    double multiplier;
    int rc;

    /* Always check to see if the file opened successfully */
    if (!fp)
    {
        /* perror() also prints a useful system error for troubleshooting */
        perror("Error opening file");
        return EXIT_FAILURE;
    }

    if (!FileLoad(fp, a, 1))
    {
        fclose(fp); /* Don't forget to close the file! */
        return EXIT_FAILURE;
    }

    /* 
        Reset both the error state and file position. 
        This way we can safely switch to write mode.
    */
    clearerr(fp);
    rewind(fp);

    printf("Please enter a multiplier: ");
    fflush(stdout); /* …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wow, that's a hideous abuse of the preprocessor.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I already gave Code::Blocks a try. Like I said in a previous comment; it is worthless. It does not compile any source code I have written, while Dev-C++ does. As long as Code::Blocks is worthless, I keep using Dev-C++.

It sounds like you tried really hard. :rolleyes: Anyway, if you're happy with Dev-C++ there's no point in switching. If you're so happy with Dev-C++ that you don't give alternatives a serious try, there's no point in switching. So don't switch; I can guarantee that nobody here will care what compiler you use unless you post non-portable code that depends on it.

p.s. On a side note, I prefer CodeLite over Code::Blocks as an IDE. My preferred IDE for more serious projects is Visual Studio 2010. But it's definitely a heavy piece of software as Mike said, so I'll use CodeLite when I need to load the IDE quickly and test something.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is it clear now?

Very clear, but C++ isn't suited to this kind of dynamic programming. A better solution would be to return a reference to the object rather than the name of a variable (which is lost during compilation).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Dev-C++ is a compiler. It compiles source codes in the language C and C++ to object code.

Dev-C++ is not a compiler, it's an IDE. The default compiler is GCC from the MinGW project, but you can actually change which compiler the IDE uses to compile your code. MinGW's GCC is fine, but the default is a very old version, so it's generally a good idea to switch the default to either a newer version or to a different compiler entirely (comeau is a good one).

I have used Microsoft Visual Studio C++ 2005 and Dev-C++. The result: Dev-C++ is more user friendly, and it has a better debugger than Visual Studio C++ 2005. I prefer Dev-C++.

You're actually the first person I've heard say that Visual Studio's debugger isn't the clear winner in usability (barring Microsoft haters, of course). I think dbg (the back-end debugger) is functional, but awkward, and the interface for it in Dev-C++ doesn't stand out compared to other debugging interfaces.

Windows 2000 is only 12 years old.

In the computing world, 12 years ago is equivalent to the bronze age. MS-DOS would be from the stone age. Comparing the bronze age with the stone age is historically interesting, but not exactly relevant if you're writing new code to be used on modern operating systems. ;)

Dev-C++ is the best compiler for each version of Windows and for Linux. :-)

In your opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your best bet to simply ask questions, and everyone who answers can be your mentor for that thread.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Couldn't find installable ISAM.

Have you read this knowledgebase article and tried the resolution steps? Also, are you sure your connection string is correct?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We could probably do it dynamically with a profile setting, but I think Dani is very much against plain text in the editor given that its highlighting capabilities are one of the primary reasons we chose it.

Is there anything broken with the highlighting such that you want to turn it off (I can try to fix bugs), or do you just not like it?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

AFAICT, we've unfortunately lost the ability to close threads...

As a moderator you can close the thread by editing it and checking the "This Article is Closed" check box.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why does the following snippet produces different result than expected?

Undefined behavior was invoked. Your expectations are invalid.

http://en.wikipedia.org/wiki/Undefined_behavior

http://c-faq.com/expr/evalorder1.html

http://c-faq.com/expr/ieqiplusplus.html

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why do you think there are soo many programming languages?

Off the top of my head:

  • Because one size doesn't fit all, and different languages suit different purposes.
  • Because computer science continues to evolve, and yesterday's language may not be suitable for today's needs.
  • Because programming language theory is interesting, and creating a language is an amazing educational tool.
  • Because new languages let us push the limits of programming theory, which produces new techniques and beneficial advancements.
  • Finally, why not? :D
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Whitespace and curly braces are used to determine whether or not you're likely to be posting code. After "Dear XYZ", you type a bunch of spaces on the next line as if you're composing a letter, which due to the indentation is error checked as code.

Any code block must be preceded by either nothing (ie. the beginning of the post) or a blank line to be highlighted properly, so we disallow any indented line immediately preceded by an unindented line.

Short answer: you're not writing a letter, so don't format your post as such. Even if you separated "Dear XYZ," with a blank line, the rest of your post would be formatted as code, which is difficult to read. So unless you intend to create a code block, please start all of your lines at column 0.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Searched all over the internet but all the programs provided are not working!!

You could try to understand the algorithm and write your own, or strive to make the programs you found work...but that might be too much to expect from today's programming students who seem to want everything given to them.

Here's a better idea: start a new thread and ask for help in understanding the algorithm or fixing one of the supposedly broken programs you've found. But before you do that, read this article.