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

What is wrong with using win32 api functions FindFirstFile() and FindNextFile() ? Can't DDK programs access win32 api?

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

A good place to begin is here. That will only scratch the surface of MS-Windows programming. A better way to learn it is to buy a book from amazon.com.

I also love www.codeproject.com, probably the largest repository of free MS-Windows code on the internet.

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

*.txt and *.ini files should be simple and straight forward to process as you described in your post. I don't know how the subject of this thread fits into that. *.docx files are more problematic because the are binary files, not text files. Other languages such as VB.NET and C# would be better suited to process *.docx files, which asre witten by Microsoft Word or Open Office.

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

And we're forgetting one ... Congrats to Sanjay for being promoted to co-Administrator! :)

Does that mean we get to curse at him when things don't go right :) LOL Just kidding. Congratulations Sanjay. You have been one of the best contributors here and you deserve the promotion.

And congrats pyTony and ardav, now you have your work cut out for you.

~s.o.s~ commented: Thanks Melvin :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

assembly

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

1) Use 64-bit version of VC++, I think its version of fstreams support huge files

2) call win32 api read/write functions which support huge files (see ReadFile() and WriteFile())

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

Why does including (float) make the difference?

Because 1/2 is integer digision, and 1 divided by 2 is 0. Make it float in a couple ways: 1) 1.0F/2.0F or 2) (float)1/2, or 3) 1.0F/2, or 4) 1/2.0F. Any of those methods are ok, just a matter of personal preference.

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

This is what I have but it isn't working in the slightest..??

That program worked ok for me using VC++ 2010 Express on Windows 7. If its broken for you then I suspect that pheininger is correct in his assessment. Change int sixdigits to long sixdigits

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

Code tags [code] [/code] don't work anymore. See the discussion in this tread

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

you will have to call strlen() to get the length of each string, add them together + 1 and malloc that much space. OR you can call realloc() in the same loop where you concantinate the strings, but you still have to call strlen() to find out how much you have to expand the destination string.

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

line 10: > )malloc(sizeof(argv)

Wrong. sizeof(argv) is always 4 because its a pointer.

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

try it again

% 0 2 d.mkv

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

I hate not having an edit button!!!

"d.mkv"

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

The above should have been "d.mkv"

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

/* For the episodes that have 0 before the number e.g 01..09 */

That's not necessary. Just use "%0.2d" and the number will have 0 before the first digit if there is only 1 digit.
char buf[50];
sprintf(buf,"\"C:\wamp\www\anime\kenshin\Rurouni Kenshin - %0d.mkv\" \"%d.mkv\"", count, count);

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

You have to format the string with sprintf() before passing it to system() or rename() functions -- those functions don't work like printf().

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

They are all violent -- do something useful with your life instead of wasting it on stupid games.

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

The derived class just calls the base classes public member functions, they can not change the value of private member data objects or call private functions.

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

That will not work with some languages that must be represented in two bytes.

If the file is in UTF-8 format then the first 4 bytes will represent a binary number between 0 and 0xffff. The table in that link tells how to interpret those bytes. If the first byte does not have a maximum value of 0x0f then the file is not in UTF-8 format. You can assume standard ascii file format, or possibly UTF-16 or UTF-32 format.

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

Here is an explanation of utf8 file format. Note that the first two bytes may be a binary integer -- see the chart at the end of that link.

Tygawr commented: Thanks for the link. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

my guess is that you failed to null-terminate the string

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

'A' - 'P' results in a negative number.

rand() % 16 + 'A'

or
rand() % ('P' - 'A') + 'A';

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

Real programmers don't need Intellisense because they have memorized the syntax or know how to read the docuomentation and all that does is slow them down :)

zeroliken commented: right :) +9
PrimePackster commented: That's a advice worth taking..... +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are passing item objects to those functions by value instead of by reference. change the function parameter list to use reference & operator so that the item struct will retain its value when control is returned to main()

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

you don't need vInt if all you are going to do is pass it to the Windows function. I don't know without testing if stringstream will work correctly like that, it may just return the char* instead of converting it to an integer.

Now that I think about it

stringstream ss;
int *iInt;
unsinged int x;
ss << argv[1];
ss >> x;
iInt = (int*)x;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

call strtol() to convert the string to an unsigned int, then assign that to a pointer of type unsigned char*.

unsigned char* ptr;
char* p;
unsigned int x = strtol(argv[1], &p, 16);
ptr = (unsigned char*)x;

or more simply

char* p;
unsigned char* ptr = (unsigned char*)strtol(argv[1],&p, 16);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Lets say you want to decrypt and the original value of str[0] == 'v'. When the loop gets to 5 it will change str[0] to 'e' and continue the loop. Now its going to look for 'e' instead of 'v', and will find it when the loop gets to 21 and change it back to a 'v'. something similar may or may not happen with all the other letters. The break statement will stop the loop when the letter is first found.

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

why don't you just try it and see for yourself if it works or not.

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

The only problem is that you have to put a break statement when the letter is found

void crypt(char str[], int strSize) {
	int i; int k;
	
	for (i = 0; i < strSize; i++) {
		for (k = 0; k < ALPHA_SIZE; k++) {
		
			if (str[i] == ALPHA[k]) {
				str[i] = CRYPT_ALPHA[k];
                break;
            }
		}
	}
}

void decrypt(char str[], int strSize) {
	int i; int k;
     
     for (i = 0; i < strSize; i++) {
         for (k = 0; k < CRYPT_ALPHA_SIZE; k++) {
             
             if (str[i] == CRYPT_ALPHA[k]) {
                 str[i] = ALPHA[k];   
                 break;

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

| is a bit operator. See this tutorial

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

strcpy() does not allocate any memory, it assumes you know what you are doing and have already allocated the required amount of memory. It also has two arguments, not just one as you posted.

Line 6 of the code you posted is also write. If you want to find out whether str points to "helloworld" then you have to call strcmp(str,"helloworld"); which will return 0 if the two strings are identical.

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

when you declare char str[] = "Hello"; the compiler allocates the exact amount of memory needed for the string. You can, if you want to, declare it like this: char str[80] = "Hello"; In that case the compiler will allocate 80 bytes of memory, initializing the first few bytes with the string. The second method is best if you know that str may eventually contain more characters, such as if you want to call strcat() to add additional characters or strcpy() to completely overwrite the existing string with something else.

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

in main(), yes and sizeof will work as expected. In the other functions its just a pointer, even when declared as char str[] in the parameter list.

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

No, that's not possible either. What is sizeof(*str)? Answer: if str is char* then sizeof(*str) will be 1, which is sizeof(char). There is no way to get the allocated size a pointer. You can call strlen() to get the length of the string, but that may or may not the the same as the allocated size.

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

In main(), replace arraysize(str) with sizeof(str)

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

Now looks like this:

int main(int argc, char *argv[]) {

	char str[] = "someword";
	int strSize = arraysize(str);

you don't need that function arraysize(). This is where you can use sizeof operator because str is not a pointer.

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

This macro

#define ARRAY_SIZE(ptr) (sizeof(ptr)/sizeof(ptr[0]))

will return the number of elements in a 1D array.

No it won't. When ptr is char* then that macro will always return 4 because sizeof(ptr) == 4 and sizeof(ptr[0]) == 1 regardless of the number of bytes allocated to the character array.

That macro only works in the function in which the character array (or any other king of array) was originally declared.

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

>>Now the next part of my plan is a way to convert this char* representation of a pointer which will be passed in, to the actual numeric value of it.

Forget that idea, it won't, and can't work for reasons previously given. Pointers can not be passed between processes because each process has its own address space. Process A can not write into process B's address space, the operating system will prevent it by producing an Access Violation type of error.

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

>>so i can skip the "int strSize = sizeof(str);" in every function.

Just as well because sizeof does not return the length of the buffer, only the size of a pointer (which on 32-bit compilers is 4). What you will probably have to do is pass the size of the array as another argument to the functions, such as void printstr(char str[], int size);

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

how big is he file? maybe you should zip it up then attach that.

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

The only difference would be to change the 4 (which is the size of a 32-bit integer) to the size of a float, whatever that is.

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

Create it exactly like you would a 1d array but twice as large. If its an integer array then it needs to be sizeof(int) * 20 * 20 bytes, or 4*20*20 = 1600 bytes.How you store the data is pretty much up to you. One way is to store all 20 integers of the first array first, followed by all 20 of the second array. So, the first integer of the first dimension would be stored at offset 0, while the first integer of the second dimension would be stored at offset 20*4 = 80 byte offset.

If you use a loop counter for data entry of all 400 integers, you can calculate the offset like this (assumes 32-bit integers):

int i = row number (0-19)
int c = column number (0-1)
int offset = (i * 20 * 4) + (c * 4)

Now just convert the above to assembly. let eax = i, ecx = c, and edx offset. I don't know mips asssembly, but just substitute those three registers in intel processors for whatever registers you have in mips.

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

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

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

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

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

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 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.