Narue 5,707 Bad Cop Team Colleague

>Do you also think that unix and programming on unix sucks?
Unix is fabulous and programming on Unix is sheer joy. X programming on Unix is what sucks. I think more programmers have lost their sanity to X than MFC.

Narue 5,707 Bad Cop Team Colleague

>Also I have googled for "windows form application in c++" and very little has comeup!
Really. None of the 35 million hits was even close to relevant? I find that hard to believe, especially when the first page looks both relevant and useful.

>How can I do this?
Handle the click event for your button. Inside the event handler, you'll create an object of the OpenFileDialog class. Once you have the path of the selected file, you can use one (or more) of the many stream I/O classes to load the contents into a string. Then copy that string into some kind of textbox control.

Salem commented: Odd that they have no trouble finding forums though.... +29
Narue 5,707 Bad Cop Team Colleague

Ooh, so close. last itself is a pointer type, so calling it an array is incorrect. I suspect you meant to say "pointer to array" but got ahead of yourself.

Narue 5,707 Bad Cop Team Colleague

clog.rdbuf(clog.rdbuf()); doesn't do anything meaningful. You've already replaced the stream buffer, so the original one is gone unless you save it elsewhere:

ofstream ofs("file.log");

// Save the original stream buffer
streambuf *clog_save = clog.rdbuf();

clog.rdbuf(ofs.rdbuf());
clog << "Logged." << endl;
ofs.close();

// Restore the stream buffer
clog.rdbuf ( clog_save );
Narue 5,707 Bad Cop Team Colleague

all_nodes is an empty vector, merge is trying to access indices that don't exist. If you want all_nodes to be populated by std::merge, you can do it with a back_inserter:

#include <iterator>

merge(from.begin(), from.end(), to.begin(), to.end(), back_inserter(all_nodes));

Alternatively you can resize all_nodes so that you no longer overrun your memory:

vector<int> all_nodes(from.size() + to.size());
Narue 5,707 Bad Cop Team Colleague

This is a risky venture because people expect array notation to have random access performance characteristics. Linked lists are not random access, and simulating random access is not only relatively expensive, it becomes more expensive as the list grows and the subscripts get larger:

Polynomial& Database::operator[] ( int i )
{
    node *it = head;

    while ( --i >= 0 )
        it = it->next;

    return it->data;
}
Narue 5,707 Bad Cop Team Colleague

The declaration syntax is probably the biggest wart C++ has. Here are a few tricks for figuring out what a declaration means, or how to write one:

  1. Simple declarations can be read backward to get the real meaning: int *p; : p is a pointer to int int **p; : p is a pointer to a pointer to int int const * const *p; : p is a pointer to a const pointer to const int

    const can be swapped with the base type without changing the meaning of the declaration: const int * const *p; : p is a pointer to const pointer to const int or p is a pointer to const pointer to an int that's const, if you want to follow the syntax closely.

  2. Direct array and function suffixes are read first then the simple declaration rules apply: int *a[10]; : a is an array of ten pointers to int int const * const *f(); : f is a function that returns a pointer to const pointer to const int.
  3. Parentheses change the evaluation order such that everything in the parentheses is evaluated first: int (*f)(); : f is a pointer to a function that returns an int. int (*a)[10]; : a is a pointer to an array of ten int.
  4. Function parameters each follow all of these rules: void f ( const int ** const (*a)[10] ); : f is a function that takes one parameter called "a" which is a pointer to an …
Narue 5,707 Bad Cop Team Colleague

I can certainly agree with well justified recommendations. But banning a feature just because it has the potential for abuse is hardly the way to educate anyone. And "discourage with extreme prejudice" does indeed amount to banning, if my experience is any indicator.

From what I've seen, the presence of goto in anyone's code always results in some know-it-all saying "never use goto!". I've even had people attempt to chastise me for using it both here and on other forums. You can imagine how well that goes. :twisted:

Narue 5,707 Bad Cop Team Colleague

>A. Whats wrong with goto
Nothing. The problem is people using it in an undisciplined way such that the code becomes an unruly mess where control flow is difficult to follow.

>B. still dosn't awnser my origonal question
Be patient. When someone is ready to give you an answer, you'll get it. I notice you didn't even bother to thank unbeatable for taking the time to help you. Did you make the suggested changes?

Narue 5,707 Bad Cop Team Colleague

>Where is the border?...
Common sense, of course. Note that I said "avoid listening to" and not "never listen to". ;) The whole reason we have this "goto is teh EBIL!!!!!" crap is because a bunch of people were mindlessly following orders rather than thinking for themselves.

Narue 5,707 Bad Cop Team Colleague

>except one thing needs a bit stronger emphasis.
>never, ever use "GOTO" this is not BASIC programming.
Note to the OP: Avoid listening to programming advice that says you absolutely must or must not do something.

Narue 5,707 Bad Cop Team Colleague

Meh, it's your call.

Let's start with some design decisions:

>void timestamp_string (char * myString)
The first thing I notice is the inconvenient notation caused by returning void. You can take a trick from the standard library and return the result string as well as let it just fall out of being a pointer parameter:

char *timestamp_string ( char *myString );

/* ... */

printf ( "Timestamped: %s\n", timestamp_string ( name ) );

That's cleaner in my opinion. The function name is also redundant. Obviously it's working with a string, so you could break it down to just timestamp, or perhaps, append_timestamp. However, when I think of a timestamp, I think of a prefix rather than a suffix. It's both easier to see in a string and easier to sort on when the timestamps is the first thing[1].

Let's do that magic and take another look:

char *prepend_timestamp ( char *s )
{
    const char fmt[] = "[%y-%m-%d %H:%M:%S]";
    const size_t n = sizeof ( fmt );
    const time_t init = time ( NULL );

    memmove ( s + n, s, strlen ( s ) + 1 );
    strftime ( s, n, fmt, localtime ( &init ) );
    s[n - 1] = ' ';

    return s;
}

The first thing that raises a flag for me is the lack of error handling. It's not possible with the current interface to verify that adding the timestamp won't overflow your string. The interface needs to change, …

jephthah commented: man, am i lucky, or what? people pay cash money for that. thanks! :) +6
Narue 5,707 Bad Cop Team Colleague

Try this and see if you get more information:

#include <cstdio>
#include <fstream>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    string filename;
    cout<<"Please type the name of the file";
    cin>>filename;
    fstream file(filename.c_str());

    cout<<filename.c_str();
    if (!file)
    {
        perror("file could not be opened");
        exit(1);
    }
    //...
}
Narue 5,707 Bad Cop Team Colleague

>le sigh.
:D

It seems you've suffered enough for that bit of code, so I'll restrain myself.

Narue 5,707 Bad Cop Team Colleague

No, you're supposed to be making changes to the Time function, since that's where the error is and that's where your code is wrong. Allow me to be more hand holdey because you clearly don't get it. Change this:

void Time(void)
{
  unsigned int Second,Minute,Hour,Date,Month,Week,Year;

  DS1302Init();
  lcd_goto(0x00);

  DS1302GetAll(Second, Minute, Hour, Date, Month, Week, Year);

  sprintf (buf," %02u/%02u/%02u% 02u:%02u",Date,Month,Year,Hour,Minute);
  lcd_puts(buf);
  printf("Date%02u/%02u/%02u\n\rTime%02u:%02u\n\r",Date,Month,Year,Hour,Minute);
  DelayMs(250);
}

To this:

void Time(void)
{
  SYSTEMTIME systime;

  DS1302Init();
  lcd_goto(0x00);

  DS1302GetAll ( &systime );

  sprintf (
    buf,
    " %02u/%02u/%02u% 02u:%02u",
    systime.Date,
    systime.Month,
    systime.Year,
    systime.Hour,
    systime.Minute );

  lcd_puts(buf);

  printf(
    "Date%02u/%02u/%02u\n\rTime%02u:%02u\n\r",
    systime.Date,
    systime.Month,
    systime.Year,
    systime.Hour,
    systime.Minute);

  DelayMs(250);
}
Narue 5,707 Bad Cop Team Colleague

>Error C208 DS1302GetAll Too many actual parameters
This is how you are declaring DS1302GetAll:

void DS1302GetAll(SYSTEMTIME *Time);

This is how you are calling it:

DS1302GetAll(Second, Minute, Hour, Date, Month, Week, Year);

I'd say your error is quite right in saying that you're passing too many actual parameters, seeing as how the function expects only 1 and you're passing seven. I suspect what you intended to do was create a SYSTEMTIME object, fill it with the data you're presently passing incorrectly to the function, then pass the object itself:

SYSTEMTIME systime;

DS1302GetAll ( &systime );
sprintf (
    buf,
    " %02u/%02u/%02u% 02u:%02u",
    systime.Date,
    systime.Month,
    systime.Year,
    systime.Hour,
    systime.Minute );
lcd_puts(buf);

The declaration and definition of DS1302GetAll (awkward name, by the way) clearly shows that the SYSTEMTIME object is an output parameter. This means that the parameter is meant to be empty to begin with and the function initializes it.

Narue 5,707 Bad Cop Team Colleague

You've made two posts in this thread with some complaint about "I can't do it, wah wah wah" and offered no code to prove that you've even tried. No offense, but I'm not encouraged to give you any more help at this point. It's beginning to feel like wasted effort on my part.

>but i have no idea how to work it.
I'm generally happy to help, but I can't give you any answers when you haven't asked any questions. "Do it for me", "tell me how to do it", or any variation thereof does not constitute a question.

This program is simple enough that I can't give you anything more complete than I already have without doing it for you. So are you going to keep crying about how you haven't a clue or are you going to actually try something and ask a specific question that we can answer without feeling guilty that we gave away the answer?

Narue 5,707 Bad Cop Team Colleague

What have you tried? Staring at your keyboard with a dumbfounded expression is unproductive, and I suspect that your teacher wouldn't have given you this assignment without providing any prerequisite information.

Here's a start:

#include <iostream>

int main()
{
    int num;

    while ( std::cin>> num )
        std::cout<< num <<'\n';
}

This reads in numbers until you signal end-of-file or type an invalid number. Now your job is to modify this code so that instead of printing the numbers immediately, the program stores them in an array and then prints them after the loop ends (with another loop).

Narue 5,707 Bad Cop Team Colleague

>Wow Narue, you are getting les and less friendly for every post aren't you?
I'm the nicest person in the world compared to my earlier posts on Daniweb.

>everybody fails now and then okay?
I have no problem with people failing. I do it regularly myself. But the way you phrased your post was "I did everything perfectly. This compiler is broken and nobody should use it".

Narue 5,707 Bad Cop Team Colleague

UPDATE:

Huge turn-off in Visual C++

I tried this VERY simple code in visual c++

#include <iostream>

using namespace std;

int main()
{
    cout << "hej lars" << endl;
    return 0;
}

And it couldn't even compile??

Yes, I imagine using your tools in a clueless way is quite a turn-off. Your code compiles just fine for me, on four versions of Visual C++ reaching back over a decade: 6.0, 2003, 2005, and 2008. Do you really think that a compiler would fail to compile the hello world program and everybody except you missed it for eleven years? Quite frankly, I don't think highly enough of you or poorly enough of the rest of the world to even entertain that possibility.

I'm more inclined to believe that you did something silly, like created a Windows application project when you wanted a console project. In other words, PEBKAC.

Narue 5,707 Bad Cop Team Colleague

>i am using windows?
You should know.

>So could be MingW?
MinGW is a port of GCC to Windows. Unless you made explicit changes to Code::Blocks settings to use a different compiler, you're using MinGW. However, regardless, you would be better off downloading Visual C++ 2008 Express as it supports not only the compiler for C++/CLI, but also a visual designer for GUIs tailored to .NET.

Narue 5,707 Bad Cop Team Colleague

>im properbly going to need a new compiler?
>(i think the one i use now is called GNU GCC?)
Yes, GCC doesn't support C++/CLI at all. The only C++/CLI compiler I'm aware of is the one used natively by Visual C++ (2005+).

>If that's the case, you will probably need to use Mono
If that's the case then his decision is made. Mono does not have a C++/CLI compiler.

Narue 5,707 Bad Cop Team Colleague

>What can .net be used for? what is it good for?
In my opinion .NET is best used for applications and services where the overhead of the framework is acceptable. I can't stress enough how much more pleasant GUI applications are to write in .NET than in Win32 or MFC. It can be used for a lot of things, and that list is growing steadily.

>.net vs. gtkmm?
.NET is much bigger than just a graphics library, so I'd say Windows Forms vs. gtkmm would be more appropriate. And I'd also say (my personal opinion) that the design of Windows Forms is superior and easier to use. Then again, I'm not a GUI programmer by any means, so easier is a huge benefit for me.

>Can i use the .net framework with c++? and how?
Yes, you just need the .NET framework and a compiler that recognizes C++/CLI. Be prepared to supplement your C++ knowledge with apparently redundant (but different) features, because C++/CLI is C++ with a bunch of extra features for supporting .NET.

>ive been googling "c++.net tut", "Visual c++ tut", ".net framework tut" etc. all day
Search for "C++/CLI", that's the official name of the new language. Also note that C++ and C++/CLI are two different languages as C++/CLI adds non-standard features to incorporate the .NET framework.

>Some say C# is easier to use with the .net net framework, is that true?
Yes. I can say without hesitation that …

tux4life commented: Very nice explanation ! :) +1
Narue 5,707 Bad Cop Team Colleague

>What are and how do I use vectors ?
Vectors and arrays are conceptually analogous. Due to operator overloading, you can use a vector in much the same way you use an array, with the added convenience of built-in functionality like automatic growth and useful information rolled up into a single object.

>I have read some tutorials on them but I don't understand fully how they work.
I could give you an implementation of the class, but I don't think that would help much. Perhaps if you show us exactly what you do and don't understand, we can fill in the blanks.

Narue 5,707 Bad Cop Team Colleague

>am i right?
Yes.

Narue 5,707 Bad Cop Team Colleague

>how do i typedef a structure
The method I usually see is a compact one:

typedef struct foo {
  /* ... */
} foo;

But you can do it your way as well (though note you have a spelling error in the typedef; it's MyStructure, not MyStucture ;)). FYI, the structure tag name space and the typedef name space are separate, which is why you can use the same name for the structure and the typedef.

>and i dont know what is identifier, and what is object here
MyStructure is an identifier, as is mystructure. When you create an instance of the structure, that's an object:

struct MyStructure foo; /* foo refers to an object */
mystructure bar; /* bar refers to an object */

>it doesnt work, no compiler errors but no swap is made
Erm, the code is pretty wrong. You don't even touch a or b, x and y don't exist unless they're global, and you want to swap the contents of the pointer, not the pointers themselves:

void swap ( mystructure *a, mystructure *b )
{
  mystructure temp = *a;
  *a = *b;
  *b = temp;
}
Narue 5,707 Bad Cop Team Colleague

>how do I sort both department and gender?
The keys are rolled up in a single object, so all you need to do is modify your comparison for the sort. Try comparing both the department and the gender in the same if statement.

Narue 5,707 Bad Cop Team Colleague

For future questions, please copy and paste the error in its entirety instead of paraphrasing. This is what the error actually says, which is different from your interpretation:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Going to the line that's specified, you find yourself at the definition of student_id (which returns an int in the declaration):

student::student_id()
{
	int sId=000;
}

Notice that there's no return type in the definition, a feature called implicit int which is not supported by C++. You can fix the error by explicitly stating the return type. A further error will be flagged because the body of this member function is nonsensical. It can be fixed as well:

int student::student_id()
{
	return sId;
}
Narue 5,707 Bad Cop Team Colleague

I think I see where you're going with this, but it's overly complicated. A better solution in my estimation would be to only store the unique strings in the temporary array, with no holes between them. What this means is that the size of the temporary array would be independent of the size of the original array, up to the size of the original array (if there are no duplicates)

This way you can treat the temporary as a conventional array and you don't have to play games like "this element is a string with one space if a duplicate occupies that index in another array":

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

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

void display_list ( char *a[], size_t n )
{
    /* You can write this */
}

int exists ( char *a[], size_t n, char *value )
{
    /* You can write this */
}

int main ( void )
{
    char *a[] = {
        "string1", "string2", "string3",
        "string4", "string2", "string1",
        "string3", "string5", "string6"
    };
    char *unique[length ( a )];
    size_t k = 0;
    size_t i;

    display_list ( a, length ( a ) );

    for ( i = 0; i < length ( a ); i++ ) {
        if ( !exists ( unique, k, a[i] ) )
            unique[k++] = a[i];
    }

    display_list ( unique, k );

    return 0;
}

>sizeof(arr) / sizeof(int)
For the record, int and char* are independent of each other. sizeof(int) is not necessarily equal to …

Narue 5,707 Bad Cop Team Colleague

This thread is being closed due to violation of Daniweb's homework policy. Read our rules, try it yourself, and then create a new thread if you need help (help != handouts, by the way).

Salem commented: The granite fist in the velvet glove comes down on another dead-end "gimme the answer" thread +29
Narue 5,707 Bad Cop Team Colleague

>why does the above code work?
Because there are only two things you can do with a function: take its address and call it. If you're not doing one, you're doing the other, and C basically ignores redundant levels of indirection on a function. This will work too:

#include <stdio.h>

int main ( void )
{
  (********&*&printf) ( "foo\n" );
  return 0;
}

>the above code prints "false 762", why?
Because you're comparing two pointers that have a different address. You don't compare strings that way because the == operator doesn't perform a content comparison on arrays, it performs a pointer comparison of the address of the arrays.

Narue 5,707 Bad Cop Team Colleague

>Please Can anyone write code?
No. If you ever get a job as a programmer, you can't say "I can't do it, you do it for me" to one of your peers. Likewise, we're here to help you become a better programmer through answers to your questions. Daniweb is not a one stop solution factory where you can get volunteer code monkeys to do your work for you.

In fact, our rules clearly state that we expect you to provide proof of effort if you want help. Please do so now or I'll close your thread on the grounds that you're in violation of Daniweb policies.

Narue 5,707 Bad Cop Team Colleague

>If there was a little bit more information to the problem he was
>having or what he needed help trying to solve than maybe it might
>have called for a bit more information and I might have added more.
I don't see any lack of information (after he described his real situation at least), but whatever you say...

Narue 5,707 Bad Cop Team Colleague

>You could loop through the array using strcmp().
Sure, a loop is pretty much required, and strcmp is the classic way of comparing strings, so no matter how this problem is solved, both of those will be used. Can you be any more vague about what you had in mind or were you just trying to sound like you know what you're talking about?

Narue 5,707 Bad Cop Team Colleague

>actually my problem is little different .
Then why did you ask about something different from your actual problem? Do you go to the auto mechanic and say that your radio isn't working when you really want the air conditioning fixed?

>Now ı want to write different colour another txt file ..how can i do that
It just so happens that the answer is the same. Cache the unique strings in an array and then write them to the second file. You can also do the original solution using file I/O, but it's tedious and inefficient.

Narue 5,707 Bad Cop Team Colleague

The simplest solution is to store the unique values in a second array. For each value in the original array, if the value doesn't exist in the second array, store it. When you've exhausted all of the values in the original array, only the unique values will be stored in the second array.

Give that a shot and feel free to ask for more help if you have any problems.

Narue 5,707 Bad Cop Team Colleague

>1) Originally on line 10 of code call was made to do left recursion
>2) Left recursion was completed printing 4 and we return to line 11 of our code.
Bingo. There's nothing special about recursion, it's just a function call. You simply happen to be calling a function with the same body as the one making the call. It couldn't hurt to do some reading on stack frames and the mechanics of function calls to solidify your understanding.

Narue 5,707 Bad Cop Team Colleague

>It's really freaking complicated
Well, duh! ;) It's not as complicated as some people (who haven't learned it and base their opinions on anecdotes) would have you believe, but programming is hard, and assembly is programming without any sugar coating[1].

>so do any of you know of any good tutorials on assembly?
Good is subjective. I wrote one that I thought was a good starting point (as mentioned already), but your first approach is the one I would recommend: search google and read everything you can get your hands on. Then try out a bunch of different assemblers. NASM and FASM are good traditionalist assemblers. HLA and RosAsm are more unique and better suited to getting your feet wet without having to figure out a lot of the prerequisites for something more traditional.

And above all, ask about anything and everything you don't understand.

[1] Unless you want to encode instructions directly with a hex editor...

Narue 5,707 Bad Cop Team Colleague

>I don't understand how it's done.
The best way to understand recursion is to walk through a small example manually. Follow your code step by step with a pencil and paper, working on the logical tree you've already provided:

6
  /   \
4      7
root = 6, left link, recurse left
    root = 4, no left link, print, no right link, return
root = 6, print, right link, recurse right
    root = 7, no left link, print, no right link, return
root = 6, return
Narue 5,707 Bad Cop Team Colleague

push and pop are std::queue's equivalent of enqueue and dequeue, respectively.

Narue 5,707 Bad Cop Team Colleague

>So this should indeed be handled with an assert
Once again it depends. If you have absolute control over the size of both vectors in the code, then an assertion is warranted because a mismatch is a logic error. If you don't have control over the size (it's based on user input, for example) then an assertion is a mistake. In the latter case I would prefer throwing an exception.

>Narue: What did you mean by "log/trace"?
Don't scuttle the boat if you can fix the problem. The majority of errors aren't fatal, and recovery is an option. But silent recovery may or may not be a good idea. In cases where you want to notify users of problems without throwing something in their face, you can write to an execution or error log that can be viewed at a later time.

Narue 5,707 Bad Cop Team Colleague

>Is there a reason that I shouldn't just do this in the first place?
It depends on your debugging needs. If the assertion is absolutely critical for the application to continue, and the information from a failed assert is sufficient, by all means use assert. On the other hand, if it's not a fatal error, you can usually log/trace and continue on. On the third hand, a lot of people replace the standard assert with their own macro that provides more helpful information.

Also remember that assert is meant to check code integrity. You're saying "This should always be true, and I'm writing code based on that assumption. If the assumption is false, the code is broken and this assert is there to keep the bug from making it to release". If the assertion fails, it's a logic bug that needs to be fixed.

I'd wager that instead of asserting that a and b will never be equal, you should be testing this as a case at runtime and producing a suitable diagnostic (ie. return value, setting errno, etc...). Otherwise, I'd immediately ask you how you know that a and b will never be equal. Are you generating those values? Do you have an explicit runtime check surrounding each call to this function?

Your example smells funny, and that makes your question suspect as well.

Narue 5,707 Bad Cop Team Colleague

Have you looked into the standard library? There's a std::unique and std::unique_copy function.

daviddoria commented: staying with a vector is better than going to a set and then back again :) +2
Narue 5,707 Bad Cop Team Colleague

It's a feature of C++/CLI, so yes, it's pretty much restricted to Visual Studio.

Narue 5,707 Bad Cop Team Colleague

>it seems that i had to cast malloc to matching type but it works great thanks
That's because you're not compiling as C, you're compiling as C++.

>cant find the right place to enable that -std=C99 flag...
IIRC (though I haven't used Code::Blocks for a few revisions), there's an advanced options box where you can type out the switches just like you would on the command line. It's somewhere in the compiler options as well.

>what compiler are you using (if yours can compile this)
If by "this" you mean the code I posted, then I used Visual Studio to compile it. However, it's standard C89, so there shouldn't be any problems with any conforming C compiler.

>p = malloc(m * sizeof *p); that sizeof *p evaluates to size of pointer to pointer
Correct. Note (because this can be confusing) that it's safe to dereference an uninitialized pointer in the sizeof expression because the expression is not evaluated. All it does is calculate the size of the resulting type in bytes.

>p = malloc(m * sizeof *p); sizeof *p evaluates to size of pointer?
Correct.

Narue 5,707 Bad Cop Team Colleague

>i dont want to think that things such as void main() are as good as int main() etc.
There's no such thing as an absolute. Even if you say that int main is better than void main, you'd be wrong. In freestanding implementations, void main is usually preferable to int main, and still conforms perfectly to the standard. Now, there are two ways you would have learned that if I hadn't told you:

  1. You filled your head with pointless trivia in the "process of extensive learning". You might even have remembered that particular tidbit of information at the crucial time when it was needed.
  2. You tried to correct someone who knew the rules and learned from the mistake. The pain of making a mistake is by far the best way to engrave knowledge into your brain.

My point is that being book smart doesn't buy you as much as you'd think. Knowing how to write perfect code in theory won't save you when you run into real world problems that theory doesn't mention. The best way to learn is to get down in the mud and learn the hard way. Even if you learn bad habits, it all corrects itself eventually if you do it long enough.

Remember that experience (ie. practice!) is your foundation, and you supplement it with things like rules and standards.

>i have actually just found -pedantic compiler flag (strict ISO C/C++)
-Wall, -ansi, and -pedantic are your friends.

Narue 5,707 Bad Cop Team Colleague

>looks like i cannot declare variable-length arrays
They're implemented, just not to the letter of the rules in the C99 standard.

>what IDE do you suggest using
>or better, what compiler and debugger
Try out as many as you can and decide that for yourself. Choice of compiler/debugger/IDE is very personal, and these days the most common ones are all equally high quality.

Narue 5,707 Bad Cop Team Colleague

>im just trying to figure the other way suggested by kenji (easier one XD)
Did I miss something, or haven't you already tried every variation of kenji's suggestion and none of them worked? If you're hell bent on following a path that isn't going to work, let me know now so I can help other people and leave you to your willful ignorance.

>1. can i declare variables and arrays wherever in my program (as
>long as i use them in same or inner scopes and after declaration)?
>(any difference c, c++?)
C89: All variables must be declared at the beginning of a block.
C99/C++: You can declare a variable anywhere you want as long as you declare it before it's used.

>2. passing a value by reference and passing a pointer to a value
>only differ in way of accessing that variables value?
C doesn't support pass by reference at all.

>3. do i pass arrays to functions by passing a pointer to first
>element of array (1 dim arrays)
Yes.

>4. argv...is it double pointer, or it is name of 2 dim array
argv is pointer to a pointer.

>what are differences if i enable c99?
The ones you'll probably care about the most are the following:

  • // comments are now standard conforming.
  • Variables don't have to be at the beginning of a block.
  • You can declare a for loop variable …
Narue 5,707 Bad Cop Team Colleague

>im using minGW GCC that comes with newest version of CodeBlocks
You have to turn C99 mode on with a switch: -std=c99.

>correct me if im wrong but you said that i need to use:
Did you completely ignore everything I said? Also, by the looks of your code you're not even using C89, much less C99. You're using C++, which doesn't support runtime sized arrays in any way, shape, or form.

Narue 5,707 Bad Cop Team Colleague

The definition of your arrays doesn't change. But if you know that there will only be ten records, 1000 is a smidge too big.