GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Aug-2006, 08:35
Allenport Allenport is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Allenport is on a distinguished road

Converting PHP to C and I need a little help


Ok so I coded something in php (what I am good at) and it keeps timing out on my server so now I am trying to do it in "C" (I have not so much experience).

Basically all I did was take my PHP code and thak the function that does the calculations and try to turn that function into C code. (I know it's sloppy )
What I need help with is fixing some of my errors and getting the code to print the results of the calculations to a text file.

CPP / C++ / C Code:
#include <stdio.h>
#include <string>
int temp_file_name, record_counter, total_requests, total_transfers, success_transfers, problem_array, fp, j, k; 
int problems_counter, line, fName, fTime, fTask, fStatus, user_array[1000], temp_name, temp_time, temp_task, t_status;

int main(int argc, char** argv){
    
}

   FILE *fp;   /* file pointer */

  /* see if correct number of command line arguments */
   if(argc !=2)
    {
      printf("File not found \n");
      exit(1);
    }

   /* open file for input */
   if ((fp = fopen(argv[1], "r"))==NULL)
    {
      printf("Cannot open file \n");
      exit(1);
    }
	

   record_counter = 0;
	while(!feof(fp))
	{
		line = fgets(fp,1024);
		line = rtrim(line);
	
		if(line == "" || strchr(line,"|") == FALSE)
		{
		
			break;
		}
		list(fName,fTime,fTask,fStatus) = split("\|",line);
		temp_file_name = strchr(fName,"/");
		temp_file_name = ltrim(temp_file_name,"/");
		temp_file_name = rtrim(temp_file_name,"/");
		if(temp_file_name == "")
			break;
		user_array[record_counter] = array(temp_file_name, fTime, fTask, fStatus);
		record_counter++;
	
	}

	total_transfers = 0;
	total_requests = 0;
	success_transfers = 0;
	problem_counter = 0;
	file_name_array_counter = 0;
	for(j = 0; j < record_counter; j++ )
	{
	
		temp_name = user_array[j][0];
		temp_time = user_array[j][1];
		temp_task = user_array[j][2];
		temp_status = user_array[j][3];
		problem_array[problem_counter] = array(temp_name,temp_time,temp_task,temp_status);
		problem_counter++;
	
		if(temp_status == "RM")
			total_requests++;
		else if(temp_status == "RE")
			total_transfers++;
		else if(temp_status == "RG")
		{
			success_transfers++;
		
			for(k = 0; k < problem_counter; )
			{
				if(temp_name == problem_array[k][0])
				{
					
					if(problem_array[k][2] == temp_task || (temp_task == "UF" && problem_array[k][2] == "DFR"))
					{
						t_status = problem_array[k][3];
						if(\problem_array[k][3] == "RF")
						{
							total_requests--;
						}
						if(problem_array[k][3] == "RE")
						{
							total_transfers--;
						}
						array_splice(problem_array,k,1);
						problem_counter--;
						if(t_status == "RG")
							break;
						if(empty(problem_array))
						{
							
							break;
						}
					
						if(problem_counter != 0 && problem_counter != k)
						{
							if(problem_array[k][0] == temp_name&& 
								problem_array[k][3] == "RG" &&
								problem_array[k][2] == temp_task)
							{
								array_splice(problem_array,k,1);
								problem_counter--;
								break; //stop searching in problem array
							}
						}
						else
							break; //problem_counter is 0 - so stop searching in problem array
					}
					else
					{
							k++;
					}
					if(empty(problem_array))
					{
						
						break;
					}
				}
				else
				{
						k++;
				}
			}
		}
	}
	
	if(!empty(problem_array))
	{
		
		process_problem_array();
	}
	if(!empty(problem_array))
	{
		
		total_requests += total_transfers;
	}
}
There are 36 errors in my code and I am stuck. Any and all help would be appreciated.
  #2  
Old 14-Aug-2006, 09:21
Allenport Allenport is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Allenport is on a distinguished road

Re: Converting PHP to C and I need a little help


Error Log (If that helps)
Code:
g++.exe "C:\Documents and Settings\David\My Documents\Test3.cpp" -o "C:\Documents and Settings\David\My Documents\Test3.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" C:\Documents and Settings\David\My Documents\Test3.cpp:13: error: expected unqualified-id before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:13: error: expected `,' or `;' before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:20: error: expected unqualified-id before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:20: error: expected `,' or `;' before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:27: error: expected constructor, destructor, or type conversion before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:27: error: expected `,' or `;' before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:28: error: expected unqualified-id before "while" C:\Documents and Settings\David\My Documents\Test3.cpp:28: error: expected `,' or `;' before "while" C:\Documents and Settings\David\My Documents\Test3.cpp:38:43: warning: unknown escape sequence '\|' C:\Documents and Settings\David\My Documents\Test3.cpp:49: error: expected constructor, destructor, or type conversion before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:49: error: expected `,' or `;' before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:50: error: expected constructor, destructor, or type conversion before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:50: error: expected `,' or `;' before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:51: error: expected constructor, destructor, or type conversion before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:51: error: expected `,' or `;' before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:52: error: expected constructor, destructor, or type conversion before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:52: error: expected `,' or `;' before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:53: error: expected constructor, destructor, or type conversion before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:53: error: expected `,' or `;' before '=' token C:\Documents and Settings\David\My Documents\Test3.cpp:54: error: expected unqualified-id before "for" C:\Documents and Settings\David\My Documents\Test3.cpp:54: error: expected `,' or `;' before "for" C:\Documents and Settings\David\My Documents\Test3.cpp:54: error: expected constructor, destructor, or type conversion before '<' token C:\Documents and Settings\David\My Documents\Test3.cpp:54: error: expected `,' or `;' before '<' token C:\Documents and Settings\David\My Documents\Test3.cpp:54: error: expected constructor, destructor, or type conversion before '++' token C:\Documents and Settings\David\My Documents\Test3.cpp:54: error: expected `,' or `;' before '++' token C:\Documents and Settings\David\My Documents\Test3.cpp:80: error: stray '\' in program C:\Documents and Settings\David\My Documents\Test3.cpp:130: error: expected unqualified-id before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:130: error: expected `,' or `;' before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:135: error: expected unqualified-id before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:135: error: expected `,' or `;' before "if" C:\Documents and Settings\David\My Documents\Test3.cpp:140: error: expected declaration before '}' token
  #3  
Old 14-Aug-2006, 09:37
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Converting PHP to C and I need a little help


If you are converting to c, then why does your file end with .cpp?

Anyway, (just for a start, there will be other errors/warnings) it looks like you have nothing in main(), because there appears to be an extra '}' in the wrong place.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
Last edited by TurboPT : 14-Aug-2006 at 10:11.
  #4  
Old 14-Aug-2006, 10:54
Allenport Allenport is offline
New Member
 
Join Date: Aug 2006
Posts: 3
Allenport is on a distinguished road

Re: Converting PHP to C and I need a little help


Quote:
Originally Posted by TurboPT
If you are converting to c, then why does your file end with .cpp?

Anyway, (just for a start, there will be other errors/warnings) it looks like you have nothing in main(), because there appears to be an extra '}' in the wrong place.
Yeah I fixed that and its cpp because I am using a C++ compiler.
  #5  
Old 14-Aug-2006, 13:38
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Converting PHP to C and I need a little help


Quote:
Originally Posted by Allenport
Yeah I fixed that and its cpp because I am using a C++ compiler.
If you are writing C, the extension needs to be C. A file ending in CPP will be built as C++, not C
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Alternative PHP Cache (APC) admin Web Hosting Forum 0 04-May-2006 23:41
PHP - sizes and generation times cable_guy_67 MySQL / PHP Forum 3 29-Sep-2005 08:26
Help ! I need help starting up on Php ! onauc MySQL / PHP Forum 11 04-Jan-2005 23:57
uisng php to display php dopee MySQL / PHP Forum 6 14-May-2004 18:40
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:03.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.