Thread: Promblem with code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    Promblem with code

    Hi to all , Yes I'm new put hoping to come here more.

    I have a program to write i logical groups

    in the code I have a problem with arugments,

    the code is in this link:
    http://www.sendspace.com/file/i5nyyi

    I know that the code is good but it's working....

    the error that I get is like this:
    "
    error C2660: 'culc_U' : function does not take 5 arguments
    "

    can SOMEbody help me?

    thanks
    Last edited by watchdogger; 01-31-2009 at 05:38 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, that error message is pretty clear to me - I can't be bothered to check the code, but it clearly says "calc_U doesn't take 5 arguments", which means that somewhere, you are passing 5 arguments to a function declared to take a different number (4 or 6 are the most likely optiones, but of course, you could have got it more wrong than that).

    Check the definition/declaration of calc_U, and compare the call that is giving you the error. My guess would be that you have either added something that shouldn't be there, or you have missed out something.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    thanks for the help man,
    I know that is the problem , I'm trying to make changes in the program. that's the problem
    when I started making the changes the problem started.

  4. #4
    a newbie :p
    Join Date
    Aug 2008
    Location
    Zurich, Switzerland, Switzerland
    Posts
    91
    that's because culc_U takes 7...while you gives only five arguments....
    Code:
    float *culc_U (const float *a, const float *b, const float *c , int size_a, int size_b, int size_c, int *pSize)  // calculate unification

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    yes so can I cahnge it to take 7 arguments....I need to take 7....

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, then you also need to PASS 7 arguments every place where the function is called.

    The error is exactly that - you are passing 5 arguments, when it expects 7.

    There is no way around this [although if you often have 2 arguments that aren't being used, you may want to add a second function that takes 5 arguments, which calls the 7-argument function with some sort of default arguments for the 2 extra arguments - if nothing else, it will make the code smaller than adding the extra 2 arguments everywhere, not to mention it saves changing every call to the function].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    thanks man,
    I didn't understand well enough what you meant.

    I want to expand my problem that way maybe somebody could help.

    This program did the following. It got a file scan it. in the file I had 3 groups on numbers
    "
    3
    u 7 -3.0 -2.0 3.2 4.4 5.55 9.1 12.12
    x 5 -2.0 3.2 4.4 5.55 12.12
    y 2 -3.0 5.55
    "

    and had a second file that has a expression:
    " xUy " for example.

    the third file got the anwser printed in it.

    Now I want the first file to have 4 groups like this:
    "
    4
    u 7 -3.0 -2.0 3.2 4.4 5.55 9.1 12.12
    x 5 -2.0 3.2 4.4 5.55 12.12
    y 2 -3.0 5.55
    z 3 4.4 5.55 12.12
    "

    and the second file has the expression:
    "xUy-z " for example.

    Soo I need to scan 4 diffrent groups in the first file to compare the groups for math problems.

    Now hope it will explain the problem I have making the changes...
    Quote Originally Posted by matsp View Post
    Well, then you also need to PASS 7 arguments every place where the function is called.

    The error is exactly that - you are passing 5 arguments, when it expects 7.

    There is no way around this [although if you often have 2 arguments that aren't being used, you may want to add a second function that takes 5 arguments, which calls the 7-argument function with some sort of default arguments for the 2 extra arguments - if nothing else, it will make the code smaller than adding the extra 2 arguments everywhere, not to mention it saves changing every call to the function].

    --
    Mats

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have no idea what you are talking about (well, ok, so I have a VAGUE idea ...) - I'm still not downloading your code to look at it for the reasons that Kermit mentioned.

    However, if there is a part of my post you don't understand, it would help if you would explain what that is. If you do not understand at all what I said, say so.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    the code for the program

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    float *culc_U (const float *a, const float *b, const float *c , int size_a, int size_b, int size_c, int *pSize)  // calculate unification
    {
    	float *temp, *result, temp_v = 0;
    	int i, j,k,l, counter = 0;
    	temp = (float *) malloc ((size_a + size_b+ size_c) * sizeof(float));
    	if (temp == NULL)
    	{
    		printf("Failed to allocate memory\n");
    		exit(1);
    	}
    	for (i=0; i<size_a; i++)
    	{
    		temp[i] = a[i];
    	}
    	j = i;
    	for (i=0; i<size_b; i++)
    	{
    		temp[j] = b[i];
    		j++;
    	}
    	l = i;
    	for (i=0; i<size_c; i++)
    	{
    		temp[k] = b[i];
    		k++;
    	}
    
    	for (i=0; i<(size_a + size_b + size_c); i++)  // sign with zero on the returning values
    	{
    		for (j=i+1; j<(size_a + size_b+size_c); j++)
    		{
    			if (temp[i] == temp[j])
    			{
    				temp[j] = 0;
    			}
    		}
    	}
    	for (i=0; i<(size_a + size_b + size_c); i++) // count how many numbers returning
    	{
    		if (temp[i] != 0)
    		{
    			counter++;
    		}
    	}
    	result = (float *) malloc (counter * sizeof(float));
    	if (result == NULL)
    	{
    		printf("Failed to allocate memory\n");
    		exit(1);
    	}
    	j=0;
    	for (i=0; i<(size_a + size_b + size_c); i++) // copying the array without the zero
    	{
    		if (temp[i] != 0)
    		{
    			result[j] = temp[i];
    			j++;
    		}
    	}
    	for (i=0; i<counter; i++)  //bubble sort
    	{
    		for (j=i+1; j<counter; j++)
    		{
    			if (result[i] > result[j])
    			{
    				temp_v = result[i];
    				result[i] = result[j];
    				result[j] = temp_v;
    			}
    		}
    	}
    	pSize[0] = counter;  // return by pointer the size of the result array
    	if (counter == 0)  // case that the group is empty
    	{
    		result = NULL;
    	}
    	return result;
    }
    
    float *culc_C (const float *a, const float *b, int size_a, int size_b, int *pSize)
    {
    	float *temp, *result, temp_v = 0;
    	int i, j, counter = 0;
    	temp = (float *) malloc ((size_a + size_b) * sizeof(float));
    	if (temp == NULL)
    	{
    		printf("Failed to allocate memory\n");
    		exit(1);
    	}
    	for (i=0; i<size_a; i++)  //copy arr a to temp
    	{
    		temp[i] = a[i];
    	}
    	j = i;
    	for (i=0; i<size_b; i++)  //copy arr b to temp
    	{
    		temp[j] = b[i];
    		j++;
    	}
    	for (i=0; i<(size_a + size_b); i++)  // sign with zero on the returning values to see the cutting
    	{
    		counter = 0;
    		for (j=i+1; j<(size_a + size_b); j++)
    		{
    			if (temp[i] == temp[j])
    			{
    				counter++;
    			}
    
    		}
    		if (counter == 0)
    		{
    			temp[i] = 0;
    		}
    	}
    	counter = 0;
    	for (i=0; i<(size_a + size_b); i++)  //counting the size of the array
    	{
    		if (temp[i] != 0)
    		{
    			counter ++;
    		}
    	}
    	result = (float *) malloc (counter * sizeof(float));
    	if (result == NULL)
    	{
    		printf("Falied to allocate memory\n");
    		exit(1);
    	}
    	j=0;
    	for (i=0; i<(size_a + size_b); i++)  //copying the result of the cutting to an array
    	{
    		if (temp[i] != 0)
    		{
    			result[j] = temp[i];
    			j++;
    		}
    	}
    	for (i=0; i<counter; i++)  //bubble sort
    	{
    		for (j=i+1; j<counter; j++)
    		{
    			if (result[i] > result[j])
    			{
    				temp_v = result[i];
    				result[i] = result[j];
    				result[j] = temp_v;
    			}
    		}
    	}
    	pSize[0] = counter;  // return by pointer the size of the result array
    	if (counter == 0)   // case that the group is empty
    	{
    		result = NULL;
    	}
    	return result;
    }
    
    float *culc_Dif (const float *a, const float *b, int size_a, int size_b, int *pSize)
    {
    	float *temp, *temp_x, *result, temp_v = 0;
    	int i, j, counter = 0;  
    	temp = culc_C (a, b, size_a, size_b, pSize);  // the array of the cutting
    	temp_x = (float *) malloc (size_a * sizeof(float));
    	if (temp_x == NULL)
    	{
    		printf("Failed to allocate memory\n");
    		exit(1);
    	}
    	for (i=0; i<size_a; i++) // copy "a" array
    	{
    		temp_x[i] = a[i];
    	}
    	for (i=0; i<size_a; i++) // set zero on repeated numbers
    	{
    		for (j=0; j<pSize[0]; j++)
    		{
    			if (temp_x[i] == temp[j])
    			{
    				temp_x[i] = 0;
    			}
    		}
    	}
    	for (i=0; i<size_a; i++)  // count without the zero
    	{
    		if (temp_x[i] != 0)
    		{
    			counter++;
    		}
    	}
    	result = (float *) malloc (counter * sizeof(float));
    	if (result == NULL)
    	{
    		printf("Failed to allocate memory\n");
    		exit(1);
    	}
    	j=0;
    	for (i=0; i<size_a; i++) // copying the array
    	{
    		if (temp_x[i] != 0)
    		{
    			result[j] = temp_x[i];
    			j++;
    		}
    	}
    	for (i=0; i<counter; i++)  //bubble sort
    	{
    		for (j=i+1; j<counter; j++)
    		{
    			if (result[i] > result[j])
    			{
    				temp_v = result[i];
    				result[i] = result[j];
    				result[j] = temp_v;
    			}
    		}
    	}
    	pSize[0] = counter;  // return by pointer the size of the result array
    	if (counter == 0) // case that the group is empty
    	{
    		result = NULL;
    	}
    	return result;
    }
    
    float *culc_SymDif (const float *a, const float *b, int size_a, int size_b, int *pSize)
    {
    	float *temp, *temp2, *result, temp_v = 0;
    	int i, j, counter;
    	temp = culc_C (a, b, size_a, size_b, pSize);
    	temp2 = (float *) malloc ((size_a + size_b) * sizeof (float));
    	if (temp2 == NULL)
    	{
    		printf("Failed to allocate memory");
    		exit(1);
    	}
    	for (i=0; i<size_a; i++) //copy the 2 arrays
    	{
    		temp2[i] = a[i];
    	}
    	j = i;
    	for (i=0; i<size_b; i++)
    	{
    		temp2[j] = b[i];
    		j++;
    	}
    	for (i=0; i<(size_a + size_b); i++)  // sign with zero
    	{
    		for (j=0; j<pSize[0]; j++)
    		{
    			if (temp2[i] == temp[j])
    			{
    				temp2[i] = 0;
    			}
    		}
    	}
    	counter = 0;
    	for (i=0; i<(size_a + size_b); i++)  // counting the array without the zero
    	{
    		if (temp2[i] != 0)
    		{
    			counter++;
    		}
    	}
    	result = (float *) malloc (counter * sizeof (float));
    	if (result == NULL)
    	{
    		printf("Failed to allocate memory");
    		exit(1);
    	}
    	j = 0;
    	for (i=0; i<(size_a + size_b); i++) // copy the variables without the zero to the new array
    	{
    		if (temp2[i] != 0)
    		{
    			result[j] = temp2[i];
    			j++;
    		}
    	}
    	for (i=0; i<counter; i++)  //bubble sort
    	{
    		for (j=i+1; j<counter; j++)
    		{
    			if (result[i] > result[j])
    			{
    				temp_v = result[i];
    				result[i] = result[j];
    				result[j] = temp_v;
    			}
    		}
    	}
    	pSize[0] = counter;  // return by pointer the size of the result array
    	if (counter == 0) // case that the group is empty
    	{
    		result = NULL;
    	}
    	return result;
    }
    
    void main()
    {
    	FILE *fp1;
    	FILE *fp2;
    	FILE *fp3;
    	int j, groups_num, size_u, size_x, size_y, size_z, size_exp = 0, size_t = 0, *p_size; // defining variables of how many groups and their size.
    	char Gu, Gx, Gy, Gz, exp, *expression;                       //    variables that contain the group name. and the expression
    	float read = 0, *u_arr, *x_arr, *y_arr, *z_arr ,*t_arr;          //   assist variable and the arrays
    	fp1 = fopen ("C:\\groups.txt", "r");
    	if (fp1 == NULL)
    	{
    		printf("Error opening file\n");
    		exit(1);
    	}
    	fp2 = fopen ("C:\\expression.txt", "r");
    	if (fp2 == NULL)
    	{
    		printf("Error opening file\n");
    		fclose (fp1);
    		exit(1);
    	}
    	fp3 = fopen ("C:\\output.txt", "w");
    	if (fp3 == NULL)
    	{
    		printf("Error opening file\n");
    		fclose (fp1);
    		fclose(fp2);
    		exit(1);
    	}
    	fscanf (fp1,"%d\n%c%d", &groups_num ,&Gu , &size_u);
    	u_arr = (float *) calloc (size_u ,sizeof(float)); // alocate memory and zero all the array
    	if (u_arr == NULL)
    	{
    		printf("Failed to allocate memory!!!");
    		exit(1);
    	}
    	for (int i=0; i<size_u && !feof(fp1); i++) // stop condition - size and end line
    	{
    		fscanf(fp1, "%f", &read);
    		u_arr[i] = read;
    	}
    	fscanf(fp1, "\r%c%d", &Gx, &size_x);
    	x_arr = (float *) calloc (size_x, sizeof(float));
    	if (x_arr == NULL)
    	{
    		printf("Failed to allocate memory!!!");
    		exit(1);
    	}
    	for (int i=0; i<size_x && !feof(fp1); i++) 
    	{
    		fscanf(fp1, "%f", &read);
    		x_arr[i] = read;
    	}
    
    	fscanf(fp1, "\r%c%d", &Gy, &size_y);
    	y_arr = (float *) calloc (size_y, sizeof(float));
    	if (y_arr == NULL)
    	{
    		printf("Failed to allocate memory!!!");
    		exit(1);
    	}
    	for (int i=0; i<size_y && !feof(fp1); i++) 
    	{
    		fscanf(fp1, "%f", &read);
    		y_arr[i] = read;
    	}
    	
    	fscanf(fp1, "\r%c%d", &Gz, &size_z);
    	z_arr = (float *) calloc (size_z, sizeof(float));
    	if (z_arr == NULL)
    	{
    		printf("Failed to allocate memory!!!");
    		exit(1);
    	}
    	for (int i=0; i<size_z && !feof(fp1); i++) 
    	{
    		fscanf(fp1, "%f", &read);
    		z_arr[i] = read;
    	}
    
    	fscanf(fp2, "%c", &exp);
    	expression = (char *) malloc (1 * sizeof(char));
    	if (expression == NULL)
    	{
    		printf("Failed to allocate memory");
    		exit(1);
    	}
    	expression[0] = exp;
    	for (int i=0; !feof(fp2); i++)
    	{
    		char *temp;
    		temp = expression;
    		size_exp++;
    		expression = (char *) malloc ((size_exp + 1) * sizeof(char));
    		if (expression == NULL)
    		{
    			printf("Failed to allocate memory!!!");
    			exit(1);
    		}
    		for (j=0; j<size_exp; j++)
    		{
    			expression[j] = temp[j];
    		}
    		fscanf(fp2, "%c", &exp);
    		expression[j] = exp;
    		free(temp);
    	}
    	p_size = (int *) malloc (1 * sizeof(int));
    	if (p_size == NULL)
    	{
    		printf("Failed to allocate memory\n");
    		exit(1);
    	}
    	for (int i=0; i<size_exp; i++)
    	{
    		char ch = 0;
    		ch = expression[i];
    
    		if (ch == 'U') // unification
    		{
    			if (((expression[i-1] == 'x') && (expression[i+1] == 'y') && (expression[i+1] == 'z')) || ((expression[i-1] == 'y') && (expression[i+1] == 'x') && (expression[i+1] == 'z')) || ((expression[i-1] == 'z') && (expression[i+1] == 'x') && (expression[i+1] == 'y')))
    			{
    				t_arr = culc_U (x_arr, y_arr, z_arr , size_x, size_y, size_z ,p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'x') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'x')))
    			{
    				t_arr = culc_U (x_arr, u_arr, size_x, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'y') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'y')))
    			{
    				t_arr = culc_U (y_arr, u_arr, size_y, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'z') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'z')))
    			{
    				t_arr = culc_U (z_arr, u_arr, size_z, size_u, p_size);
    				expression[i+1] = 't';
    			}
    
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'x')) || ((expression[i-1] == 'x') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_U(t_arr, x_arr, size_t, size_x, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'y')) || ((expression[i-1] == 'y') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_U(t_arr, y_arr, size_t, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'z')) || ((expression[i-1] == 'z') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_U(t_arr, z_arr, size_t, size_z, p_size);
    				expression[i+1] = 't';
    			}
    			else
    			{
    				if (((expression[i-1] == 't') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 't')))
    				{
    					t_arr = culc_U(t_arr, u_arr, size_t, size_u, p_size);
    					expression[i+1] = 't';
    				}
    			}
    			
    		}
    
    		if (ch == '^') //cutting
    		{
    			if (((expression[i-1] == 'x') && (expression[i+1] == 'y')) || ((expression[i-1] == 'y') && (expression[i+1] == 'x')))
    			{
    				t_arr = culc_C (x_arr, y_arr, size_x, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'x') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'x')))
    			{
    				t_arr = culc_C (x_arr, u_arr, size_x, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'y') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'y')))
    			{
    				t_arr = culc_C (y_arr, u_arr, size_y, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'x')) || ((expression[i-1] == 'x') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_C (t_arr, x_arr, size_t, size_x, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'y')) || ((expression[i-1] == 'y') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_C (t_arr, y_arr, size_t, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else
    			{
    				if (((expression[i-1] == 't') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 't')))
    				{
    					t_arr = culc_C (t_arr, u_arr, size_t, size_u, p_size);
    					expression[i+1] = 't';
    				}
    			}
    		}
    
    		if (ch == '-') // difference
    		{
    			if ((expression[i-1] == 'x') && (expression[i+1] == 'y')) 
    			{
    				t_arr = culc_Dif (x_arr, y_arr, size_x, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'y') && (expression[i+1] == 'x'))
    			{
    				t_arr = culc_Dif (y_arr, x_arr, size_y, size_x, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'x') && (expression[i+1] == 'u')) 
    			{
    				t_arr = culc_Dif (x_arr, u_arr, size_x, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'u') && (expression[i+1] == 'x'))
    			{
    				t_arr = culc_Dif (u_arr, x_arr, size_u, size_x, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'y') && (expression[i+1] == 'u'))
    			{
    				t_arr = culc_Dif (y_arr, u_arr, size_y, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'u') && (expression[i+1] == 'y'))
    			{
    				t_arr = culc_Dif (u_arr, y_arr, size_u, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 't') && (expression[i+1] == 'x'))
    			{
    				t_arr = culc_Dif (t_arr, x_arr, size_t, size_x, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'x') && (expression[i+1] == 't'))
    			{
    				t_arr = culc_Dif (x_arr, t_arr, size_x, size_t, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 't') && (expression[i+1] == 'y'))
    			{
    				t_arr = culc_Dif (t_arr, y_arr, size_t, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 'y') && (expression[i+1] == 't'))
    			{
    				t_arr = culc_Dif (y_arr, t_arr, size_y, size_t, p_size);
    				expression[i+1] = 't';
    			}
    			else if ((expression[i-1] == 't') && (expression[i+1] == 'u'))
    			{
    				t_arr = culc_Dif (t_arr, u_arr, size_t, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else
    			{
    				if ((expression[i-1] == 'u') && (expression[i+1] == 't'))
    				{
    					t_arr = culc_Dif (u_arr, t_arr, size_u, size_t, p_size);
    					expression[i+1] = 't';
    				}
    			}
    		}
    		if (ch == '*')  // symmetrical difference
    		{
    			if (((expression[i-1] == 'x') && (expression[i+1] == 'y')) || ((expression[i-1] == 'y') && (expression[i+1] == 'x')))
    			{
    				t_arr = culc_SymDif (x_arr, y_arr, size_x, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'x') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'x')))
    			{
    				t_arr = culc_SymDif (x_arr, u_arr, size_x, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 'y') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 'y')))
    			{
    				t_arr = culc_SymDif (y_arr, u_arr, size_y, size_u, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'x')) || ((expression[i-1] == 'x') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_SymDif (t_arr, x_arr, size_t, size_x, p_size);
    				expression[i+1] = 't';
    			}
    			else if (((expression[i-1] == 't') && (expression[i+1] == 'y')) || ((expression[i-1] == 'y') && (expression[i+1] == 't')))
    			{
    				t_arr = culc_SymDif (t_arr, y_arr, size_t, size_y, p_size);
    				expression[i+1] = 't';
    			}
    			else
    			{
    				if (((expression[i-1] == 't') && (expression[i+1] == 'u')) || ((expression[i-1] == 'u') && (expression[i+1] == 't')))
    				{
    					t_arr = culc_SymDif (t_arr, u_arr, size_t, size_u, p_size);
    					expression[i+1] = 't';
    				}
    			}
    		}
    
    
    		if ((i%2) != 0)  // change later to another stopping  condition - if i have ~ or - or * or * or U
    		{
    
    			size_t = p_size[0];  // update the size of the array
    		}
    	}
    
    	if (t_arr == NULL)  //  case the final group is empty 
    	{
    		printf("Empty Group\n");
    		fprintf(fp3, "Empty Group\n");
    	}
    	else   // not empty
    	{
    		for (int i=0; i<p_size[0]; i++)  // loop to check and print the array on the screen
    			{
    				printf("%f   ", t_arr[i]);
    			}
    
    		for (int i=0; i<p_size[0]; i++)  // print the result array to file "output.txt"
    		{
    			fprintf(fp3, "%f ", t_arr[i]);
    		}
    	}	
    }

  10. #10
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Quote Originally Posted by watchdogger View Post
    This is not related to the problem, but as a suggestion, don't use free file storage places like this; I would say that it tends to decrease your chances of getting help. The reasons for this are various, such as having to wait for 20 seconds or whatever watching a countdown timer, then getting the file, and having to reformat it from your Windows carriage returns to the Unix concept of newlines. The formatting quite often gets munged up in the process, and when the file is this big, people give up. Better to post your (neatly formatted) code here, even if it is larger, with code tags. Best of all, post the smallest working example of your problem.

  11. #11
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    first of all I posted the code here.
    Second I understood your answer but I have a problem how to change it in the code.

    thanks kermit I just added the code...

  12. #12
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    Yes, I changed the first one yeah but in the other parts I don't which arg to use because I don't use others...

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by watchdogger View Post
    Yes, I changed the first one yeah but in the other parts I don't which arg to use because I don't use others...
    Right. So why do you have 7 arguments in the first place? Because you have three arrays, and each has a size argument, and then you need a result size as well.

    Oh, and a few more comments on your code:
    Code:
        pSize[0] = counter;  // return by pointer the size of the result array
    Whilst this does indeed set the location pointed to by pSize to counter, it is probably a better option to do:
    Code:
        *pSize = counter;  // return by pointer the size of the result array
    since pSize is not an array of one element, it is the address of a single integer. [and please do not allocate 1 integer's worth of space. Use a local variable and take it's address, e.g.
    Code:
    int resultSize; 
    ... 
    result = culc_U(...., &resultSize);
    Do not use standard names for variables:
    Code:
     size_t
    Bad name for a variable - there is a standard type called size_t. You wouldn't call a variable "int" or "float", would you?

    Code:
        int j, groups_num, size_u, size_x, size_y, size_z, size_exp = 0, size_t = 0, *p_size;
    Do not mix initialize and uninitialized variables on the same line - it's hard to follow (I personally also dislike LONG lists of variables on one line - if there are two or three closely connected variables, they may be on the same line - but not 8 different variables which aren't closely connected).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    Thank you very much for ur help I learn this way how to improve my programming.

    I will make the changes that u show me.

    But how do I make the changes I need?
    I don't where to make the changes...

  15. #15
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    Thanks again but to correct you I have 4 arrays not 3.

    That's the biggest change I need to work with now in the code.

    That's where my problem starts.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM