Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't really matter what n means, when n == 50, q[n] is an invalid value because there are not 51 elements in q. Same problem with nfa becauswe nfa[0][n] is invalid.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No. The value of n is the number of elements to check. So the program needs to count from 0 to n-1. Count them on your fingers if you have to get this concept straight in your head. When the value of n == 10, count 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 -- that's 10 items

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you put line 15 in the wrong place. It has to go after line 30, after you enter the text to be encrypted. It can't remove spaces if there is nothing in the char array yet.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It could have everything to do with it when your program corrupts memory anything can happen at the most unexpected times. Fix the loop problems then retest.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

somewhere in main() RemoveSpaces(clear); Or replace variable clear with cipher.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't understand your question. All you do is call that function from main() with the string that you want to have it work with. When RemoveSpaces() finishes the string in main() will not have any white spaces in it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> for(j=1;j<=n;j++)
lines 88, 94 and 97

should by j<n to avoid array out-of-bounds errors -- same with other lines that contain similar loops.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is the loops in out_plane(), loop counters exceeding the bounds of those arrays.

void out_plane(char *component,char *plane,float value,char *lastname,long tt)
{
	FILE *file;
	char name[20];
	int i,j,k;
	int i_range, j_range, k_range; 
	// for Hz_parity, normal cases
	i_range = isize-1;
	j_range = jsize-1;
	k_range = ksize-1; 
	
	if(use_periodic_x == 1)
		i_range = isize;
	if(use_periodic_y == 1)
		j_range = jsize; 
	
	sprintf(name,"%07d",tt);
	strcat(name,lastname);
	file=fopen(name,"w");

	if(strcmp("x",plane)==0)
	{
		i=floor(0.5+((value+xcenter)*lattice_x));
		for(k=k_range-1;k>=1;k--)
		{
				for(j=1;j<j_range;j++)	fprintf(file,"%g ",grid_value(component,i,j,k));
				fprintf(file,"\n");
		}
	}

	if(strcmp("y",plane)==0)
	{
		j=floor(0.5+((value+ycenter)*lattice_y));
if(tt<tendrecord)
{
 for (k=k_range-1;k>=0;k--)
 {
				for(i=1;i<i_range;i++)	
				{if(strcmp(component,"Ex")==0)
                 {Ex_yplane_measure_cos[i][k][1]+=grid_value(component,i,j,k)*cos(2*pi*freqmeasure*tt*(a_n*1E-9)/(light_speed*S_factor*ds_x*lattice_x));
                 Ex_yplane_measure_sin[i][k][1]+=grid_value(component,i,j,k)*sin(2*pi*freqmeasure*tt*(a_n*1E-9)/(light_speed*S_factor*ds_x*lattice_x));
                 }
                 else if(strcmp(component,"Ez")==0)
				 {Ez_yplane_measure_cos[i][k][1]+=grid_value(component,i,j,k)*cos(2*pi*freqmeasure*tt*(a_n*1E-9)/(light_speed*S_factor*ds_x*lattice_x));
				 Ez_yplane_measure_sin[i][k][1]+=grid_value(component,i,j,k)*sin(2*pi*freqmeasure*tt*(a_n*1E-9)/(light_speed*S_factor*ds_x*lattice_x));
                 }
				 else if(strcmp(component,"Hy")==0)
				 {//////IF ERROR IN RESULT LOOK AT FFT OF FARFIELD.C
                 Hy_yplane_measure_cos[i][k][1]+=grid_value(component,i,j,k)*cos(2*pi*freqmeasure*tt*(a_n*1E-9)/(light_speed*S_factor*ds_x*lattice_x));
                 Hy_yplane_measure_sin[i][k][1]+=grid_value(component,i,j,k)*sin(2*pi*freqmeasure*tt*(a_n*1E-9)/(light_speed*S_factor*ds_x*lattice_x));
                 }
				 else {}
                 }
  }               
}
else
{if(strcmp(component,"Ex")==0)
		for(k=k_range-1;k>=1;k--)
		{
				for(i=1;i<i_range;i++)	fprintf(file,"%g ",sqrt(Ex_yplane_measure_cos[i][k][1]*Ex_yplane_measure_cos[i][k][1]+Ex_yplane_measure_sin[i][k][1]*Ex_yplane_measure_sin[i][k][1]));
				fprintf(file,"\n");
		}
else if (strcmp(component,"Ez")==0)
		for(k=k_range-1;k>=1;k--)
		{
				for(i=1;i<i_range;i++)	fprintf(file,"%g ",sqrt(Ez_yplane_measure_cos[i][k][1]*Ez_yplane_measure_cos[i][k][1]+Ez_yplane_measure_sin[i][k][1]*Ez_yplane_measure_sin[i][k][1]));
				fprintf(file,"\n");
		}
else if (strcmp(component,"Hy")==0)
		for(k=k_range-1;k>=1;k--)
		{
				for(i=1;i<i_range;i++)	fprintf(file,"%g ",sqrt(Hy_yplane_measure_cos[i][k][1]*Hy_yplane_measure_cos[i][k][1]+Hy_yplane_measure_sin[i][k][1]*Hy_yplane_measure_sin[i][k][1]));
				fprintf(file,"\n");
		}
else {}		
	}
}
	if(strcmp("z",plane)==0)
	{
		k=floor(0.5+((value+zcenter)*lattice_z));
		for(j=j_range-1;j>=1;j--)
		{
			for(i=1;i<i_range;i++) fprintf(file,"%g ",grid_value(component,i,j,k));	
			fprintf(file,"\n");
		}
	}
	fclose(file);
	printf("out %s...ok\n",component);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you will have to port the c++ code to cli/c++ (managed code) then put it in a DLL. If you don't know how to create a dll then learn how to do it -- here is a tutorial.

Next read through a couple of these google links to find out how to call the dll from C#.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Also, was temp initialized before calling strcat() the first time? eg. char temp[50] = {0};

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

As for your scanf problems, you might want to consider switching to getline().
http://crasseux.com/books/ctutorial/getline.html

This is the C forum and program, not c++, so using getline() is not an option.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Too bad C doesn't have an ArrayList class like Java or Vector like in C++ ;)

Then it wouldn't be C, would it? :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

here is one way to do it

void RemoveSpaces(char *str)7
{
   int i = 0;
   int length = strlen(str);
   while(i < length)
   {
      if( isspace(str[i]) )
      {
         memmove(&str[i], &str[i+1], length-1);
         --length;
      }
      else
          ++i;
   }

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One of the problems is that line 55-66 is calling that function with too few arguments. float_3d_memory() takes three arguments, not two.

Pay close attention to the errors and warnings that your compiler gives you. If it doesn't give you any then you need to increase the warning level. How to do that depends on the compiler you are using. I used vc++ 2010 express on Windows 7 and got 26 errors like the one I mentioned above.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It would be alot simpler if you stored the words in a structure so that the English and French words can be kept together.

struct words
{
    char English[max_word_len];
    char French[max_word_len];
}

Then make an array of structures struct words array[40]; You might also have to change the functions to accept array of structures void sort_words(struct words array[], int nitems);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One crevet you need to know about fgets() -- it frequently puts '\n' at the end of the string which you will need to erase.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome Granny :) This is Grandpa, also retired military :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> I really need it to work with full names though
See my previous post how to fix it.

>> One more thing, why do you think that my previous struct studentName variable was incorrect?

It was incorrect because all you declared was a pointer, and there is no memory attached to pointers. The change I made to your structure provides enough room to enter 40 characters as the name. Pointers do not allow for any room unless you specifically call malloc() to allocate the memory.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What did you enter for each of the questions? scanf() using "%s" does not accept spaces in text you enter so you have to enter studentName as only one word. If you want to be able to enter two or more words for studentName then use fgets() instead of scanf(), e.g. fgets(list[x].studentName, sizeof(list[x].studentName), stdin);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Too bad our instructor wants all compilations on the server's gcc

Your instructor is probably using *nix

>>I'll fire up vc++ and try it out myself then.
Make sure to correct the problem with that structure.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

gcc might make a difference. I'm using vc++ 2010 express on Windows 7 and it worked with that compiler.

There is another problem with that structure -- see studentName below

struct Student
{
	int studentNumber;
	int phoneNumber;
	char studentName[40];
};

I compiled it with Code::Blocks and MinGW (port of gcc) and it worked ok too

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

struct Student
{
	int studentNumber;
	int phoneNumber;
	char studentName[40];
};

int main()
{
	struct Student *list;
	int numOfStudents;
	int x;
	int studentCounter = 1;

	printf("\nPlease enter the number of students you would like to input: ");
	scanf("%d", &numOfStudents);
getchar();
	list = malloc(sizeof(list) * numOfStudents);

	for(x = 0; x < numOfStudents; x++)
	{
		printf("\nPlease enter name for student #%d: ", studentCounter);
		scanf("%s", list[x].studentName);
		printf("Please enter student number for student #%d: ", studentCounter);
		scanf("%i", &list[x].studentNumber);
		printf("Please enter phone number for student #%d: ", studentCounter);
		scanf("%i", &list[x].phoneNumber);
getchar();

		studentCounter++;
	}


}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One common way is to allocate memory in fixed block sizes. When that fills up then allocate a larger array. Here is an example

int array_size = 0; // initial array size
int elements_used = 0; // current number of elements used in the array
int *array = NULL; // initial array is empty

#define BLOCKSIZE 10 // allocate this many elements at a time

int main()
{
   int number = 0;
   for(;;) // infinite loop
   {
      printf("Enter a number\n");
      scanf("%d", &number);
      // check for array overflow
      if( (elements_used+1) >= array_size)
      {      
          // stretch the array
          array_size += BLOCKSIZE;
          array = realloc(array, array_size);
      }
      array[elements_used] = number;
      ++elements_used;
   }
}
DarkMonarch commented: helpful tip +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need two of them -- after lines 19 and 30. Note that phone number should be a character array so that you can enter dashes like 555-555-5555 or (555) 555-5555

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When you enter a number you have to press the <Enter> key, right??? Well, scanf() leaves that '\n' <Enter> key in the keyboard so the next time scanf() or some other keyboard function is called all it will get if the '\n' Enter key.

what you have to do is flush out that '\n' byte in the keyboard buffer after entering numeric data, e.g. call getchar() after scanf(). That may, or may not, be a complete solution if you enter a lot of keys after entering the numeric data, for example if you enter "123abc\n" scanf() will pick up the 123 and put it into the numeric variable but leave the rest of the stuff in the keyboard buffer. Unfortunately there is no standard solution to flushing out all the stuff in the input keyboard buffer. There are a few non-standard solutions but they are compiler dependent which may or may not work with your instructor's compiler should he/she want to compile your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. Move those two huge arrays on lines 15 and 16 up above main() so that they will not be on the limited stack.


2. All array idices are numbered 0 to, but not including, the declared array size. So an array with 800 elements are numbered 0 to 799.

The two loops on lines 26 and 27 exceed the limits of those two arrays by 1 element each. You need to modify them as shown below.

for (k=k_range-1;k>=0;k--)
  for(i=0;i<i_range;i++)

3. There is no point in declaring those two arrays on lines 15 and 16 as 3dimensional arrays -- 2-dimensional arrays is sufficient for your purposes

float Hy_yplane_measure_cos[800][999];
float Hy_yplane_measure_sin[800][999];

4. change line 29 like this (its wrong as you posed it): Hy_yplane_measure_cos[i][k]+=1*cos(2*3.1416*freqmeasure*tt*(a_n*1E9)/(light_speed*S*lattice_x))

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to find out what compiler you will be using and whether it is ansi C compliant. If it is, then it will support all the functions in stdio.h. If not then you may have limited options and have to convert from int to char* yourself (e.g. write your own simple version of sprintf without all the bells and whistles that the standard C version has).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I use a smartphone to check email as my boss sends me about 400 a day.

Wow! How on earth does he expect you to get any work done?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why can't you use functions in cstdio?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See the example program at this link, and while you are there you might want to bookmark that link so that you can use it for future reference.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It might depend on what language you want to write your program with. excel spreadsheets are very difficult, if not impossible, to work with in most languages (vb.net is one exception). A better and more portable solution is to create a database with either MS-Access (not free) or MySQL (free)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't use any of them -- just a PC, simple and cheap Sprint cellphone (with no internet connection) and a Samsong tablet.

>>I know it’s a question that is not only as old as time itself
You aren't very old, are you :) :) They've only been around since 1999, just 12 short years.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to convert the integer to a char*, not char.

char score2[20];
sprintf(score2,"%d", score);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13: exit is the name of a standard c or c++ function. Give that variable a different name.


line 1163: don't call main() anywhere in your program. That function should only be called by the operating system. If you need to repeat the code that is in main() then put a loop in that function.


Next time post line numbers with those error messages so that we know where to look in your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I know of no way to do that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to format that char* before calling TextAdd(). There are several ways to format it, one way is to use std::stringstream from <sstream> header file, another way is to use sprintf().

#include <sstream>

int main()
{
   int score = 123;
   stringstream str;
   str << score;
   std::string s;
   s = "Score: ";
   s += str.str();
}

or

#include <cstdio>

int main()
{
   int score = 123;
   char text[80];
   sprintf(text,"Score: %d", score);
}
SgtMe commented: just what I needed...thanks :) +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The links don't work. Its better to just use he Advanced Editor (link at the underneath the message editor) and upload the pictures to your thread.

#include <iostream>
#include <string>

Those are c++ header files, not C. You can't compile that program with a C compiler.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That is only one way to do it. A more generic way would be to first convert the int to string, then copy the digits in reverse order (from right to left) into another string adding the commas. Finally you will have to reverse the result string because it will be backwards. std::reverse() will do that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Line 12 is pretty much useless. If LoadLibrary() fails then there is no reason to call FreeLibrary(). Call FreeLibrary() only when the process is done using it. Also, add an error message and return on line 13 when LoadLibrary() fails.

Why it fails to work the second time, I don't know.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The reason is there is a maximum value that an integer can hold -- the maximum is declared in the header file limits.h that is supplied by your compiler. What you are seeing is called numeric overflow.

If you need bigger numbers then use a bigger integer, such as "long long", which holds about twice as many digits as an int or long. There are no standard C or C++ data types that will hold an infinite number of digits.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

when I went on holiday to Vietnam in 1999.

How times change :) When I went on holiday there for a year in 1967 it was a war zone.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Me too facing the same problem. I tried with other browsers too.:-/
Every time am trying refresh(postback) to submit a post.

Make sure your computer allows cookies.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use getline() instead of >> operator. fin.getline(string2, sizeof(string2)); Or if you use std::string

std::string string2;
getline(fin, string2);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Really?? How do you get ardav out of mississippi?

iamthwee commented: +1 for satire +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what's the question??

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That code didn't work for me so I modified it. This code will work for any situation that someone needs to use the up arrow, down arrow, left arrow, and right arrow.

The problem with your program is that there is no difference between F1 and a semicolon because they both have the same ascii value. Same with all the other special keys you defined. That's why I added 255 to the ascii value for special keys so that the program would be able to distinguish them from normal keys. Some programmers just make the value of special keys negative, e.g. #defind F1 (-59)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 30-32: the value of k is a negative number when i is 0. Do the first time through using k as index is illegal because there is no such thing as -1 index of arrays.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

"compile-time" is when the compiler compiles the program. "run time" is when you actually execute the program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's not possible unless you are writing a compiler and then it would be a compile-time check, not a runtime check.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

compiled ok for me

#include <iostream>

using namespace std;

int main()
{
    long long x = 123;
    cout << "Hello world! " << x << endl;
    return 0;
}