Anarion's Profile User Rating: -----

Reputation: 311 Architect
Author w/DIC++
Active Posts:
1,513 (0.74 per day)
16-May 09
Profile Views:
Last Active:
User is offline Today, 05:04 PM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Favorite Gaming Platform:
Your Car:
Who Cares
Dream Kudos:

Latest Visitors

Icon   Anarion has not set their status

Posts I've Made

  1. In Topic: Iterators problems

    Posted 26 Dec 2014

    std::vector::begin() returns a random access iterator, which does not support addition of two iterators by using operator+ and therefore, your code does not compile. The supported arithmetics for a random access iterator are:
    • iterator + integer
    • integer + iterator
    • iterator - integer
    • iterator - iterator

    Though as CTphpnwb said, what you are doing in that line does not make sense aside from calling an undefined operator+.
  2. In Topic: Project Euler Question 5

    Posted 26 Dec 2014

    Well, you got it right about the usage of array to store 1-20. Lets walk through:


    Initialize variable to hold the current number
    Loop begin
    --- if the current number is a valid solution then
    ------ stop the loop
    --- increment the current number and continue looping
    Loop end
    Print the solution

    For checking the valid solution condition, you can write a separate function that accepts an argument and returns true if this argument meets the right conditions (here arrays come in handy).

    Initialize an array to contain the numbers 1-20, then you can easily loop through it and check the conditions.

    Edit: fixed the indentation. Also, your method would be a brute-force solution that checks every single element. You can further analyze the problem and eliminate many of these possible answers to reduce calculations.
  3. In Topic: Uses for C & C++

    Posted 25 Dec 2014

    +1 for what Jim said.

    C and C++ have things in common, but it's better to say they just have common roots in the old times! Even the new C++ standard (C++11 and C++14) may feel like a new language when compared to C++98. Because of these differences, it's not a good approach at all to learn C in order to better learn C++.

    Learn the one that is more practical for your needs. I started C++ as a hobby and because I really likes programming. The bad thing was, the book taught C++ as a modified version of C and therefore I learned pretty bad practices at first.
    Nowadays, I write scientific programs completely in C++. There are tons of scientific libraries and programs out there that are in C/C++.
  4. In Topic: Dennis Labs Test : Oh look, AVG & MSE are the worst

    Posted 25 Dec 2014

    +1 for Malwarebytes, even the non-premium version without active monitoring is pretty useful in cleaning up the whole system. Have also used Avira for a few systems in dormitories as my friend asked for help securing them. The separate update tool was quite handy!

    Thanks for sharing this link :)
  5. In Topic: break out of loop when a certain word or phrase is entered

    Posted 24 Dec 2014

    I am much more into C++ than C but, I think you should read about strcmp, it is used to compare two strings and returns 0 if the two compared strings are equal. Using this, you can improve this function:
    int ex(char arr[]){
    	int i;
    	int val;
    	for (i = 0; i < 5; i++){
    		if(arr[0] == 'e' && arr[1] == 'x' && arr[2] == 'i' && arr[3] == 't' && arr[4] == '\n'){
    			val = 1;
    		}else {
    			val = 0;
    	return val;

    int ex(char arr[])
       int val;
       if(strcmp(arr, "exit") == 0) {
          val = 1;
       } else {
          val = 0;
       return val;

    You may expect the above to work as it might seem so at first. But there is one more thing: fgets reads in the newline character as well! So basically if I write "exit" and press Enter, the string is "exit\n" which is not equal to "exit"!

    A not-so-good-but-working fix would be:
       if(strcmp(arr, "exit\n") == 0) {
          val = 1;
       } else {
          val = 0;

    But a more robust fix is to check if the string contains a newline character and replace it with a null character:
    int main()
       char *string, *p;
       string = (char*)malloc(70 * sizeof(char));
       if(string == NULL) {
          printf("Error! Memory not allocated!");
       while (1) {
          printf("Enter a string!!!\n");
          fgets(string, 70, stdin);
          /* Check for newline, replace with null if it was there */
          if ( (p = strchr(string, '\n')) != NULL ) {
             *p = '\0';
          if (ex(string) == 1) {
          mixcase(string, 70);
          printf("%s\n", string);
       return 0;

    strchr returns a pointer to the first occurrence of a certain character in the string. Read more about it here.
    Also, there is a tutorial here on using fgets and dealing with the newline problem.

    Last but not least, you are allocating memory but you forgot to free it in the end! Never forget to do so:
    int main()
       char *string, *p;
       string = (char*)malloc(70 * sizeof(char));
       if(string == NULL) {
          printf("Error! Memory not allocated!");
       /* Do Stuff! */
       return 0;

    Edit: As noted by Jim, there really was no need for a dynamic allocation. But when you do it, you are responsible to free it! That's one of the reasons for avoiding it when you can.

My Information

Member Title:
The Persian Coder
22 years old
May 17, 1992
Music, Tennis, Programming, KitKat, Cars, Bikes
Full Name:
Kian Nezhadfard
Years Programming:
Programming Languages:
Good At: C++
Know some: PHP, Bash
Learning: Python, R

Contact Information



Page 1 of 1
  1. Photo

    Hybrid SyntaX Icon

    10 Feb 2014 - 14:02
  2. Photo

    estherNamogo Icon

    03 Nov 2013 - 06:33
    Nice to meet you write
    me at ( i will send you my picture OK.
  3. Photo

    jatinjindalj Icon

    06 Sep 2012 - 09:01
    Hey Regarding your code snippet at>
    Can you please explain:
    why when at line 37 and 38,If I do
    while(q!= NULL) {//Line 37
    q = q->link;
    t = new node;
    t->data = str;
    t->link = NULL;<...
  4. Photo

    Anarion Icon

    07 Aug 2012 - 06:23
    Thanks! I had made it for DIC Signature Contest and put it on my sig since then.
  5. Photo

    AnalyticLunatic Icon

    06 Aug 2012 - 09:05
    Just wanted to drop by and say Sweet Sig. Sometime I need to make one for myself.
  6. Photo

    David W Icon

    07 Jun 2012 - 00:31
    Shalom shalom my Regal Persian Coder Friend
  7. Photo

    Anarion Icon

    16 Mar 2011 - 00:56
    @abrsefid: ba arze sharmandegi, komaki az man sakhte nist. Az beine portha faghat ba USB kar kardam oon ham dar sathe kheili payin. Be shoma pishnahad mikonam baraye javabe soaletun dar internet jostejoo konid :)
  8. Photo

    yogesh201010 Icon

    05 Mar 2011 - 18:41
    hi i am yogesh
    how to connect internet by mob in linux.
    and tell me book for linux learning
  9. Photo

    abrsefid Icon

    27 Feb 2011 - 05:23
    salam man donbale 1 code c++ (ubuntu) migardam vase send o receive data ba port serial mishe rahnamaeem konid ?
  10. Photo

    hamishehiran Icon

    10 Aug 2010 - 23:02
    thanks for add! ;) nice to meet you!
  11. Photo

    Anarion Icon

    28 Mar 2010 - 08:27
    Thanks! Happy new year to you too :)
  12. Photo

    saSBH2 Icon

    28 Mar 2010 - 07:03
    Happy New Year :)
Page 1 of 1