Thanks. This is just a test of concept program so I'm not doing 'real' variable names. As a former VB person I'm still in the CCAC (code cuss and cry) phase of learning C:)
Jeffrey Webster
Posts
-
Reading a comma delimited file to array -
Reading a comma delimited file to arrayThanks Richard, I'm going to try to track down the errors in this code first and then experiment with this tokenizer. At this point I'm trying to get a really granular understanding of C which even means reinventing the wheel at times, just for my own edification:)
-
Reading a comma delimited file to arrayHi, thanks for your response. That helped. I also changed the control in the inside printf loop to
for(l=0;*(str2[j]+l);l++)
Now it's compiling with no warnings and is reading back pretty good text, though there is some stray characters after some of the words in the test text.
-
Reading a comma delimited file to arrayHi, Thanks for the reply. As far as I can see that's what I have except without the assignment to the array:
str2[j][l]=k
but that is basically what I'm trying to accomplish. The printing at the end is just to confirm that the file was successfully written to the array.
-
Reading a comma delimited file to arrayHi, I'm hitting a snag as I try to read back an array which has been written to a text file. Here's the relevant part of the code:
if((fp=fopen("myfile","r"))==NULL)
{
printf("Unable to open file.\n");
exit(1);
}
for(j=0;j<6;j++)
{
for(l=0;l<7;l++)
{
k=fgetc(fp);
if(k==",") break;
str2[j][l]=k;}
}
fclose(fp);
for(j=0;j<6;j++)
{
for (l=0;l<7;l++)
{
printf("%c", str2[j][l]);
}
}This is generating an error: [Warning] comparison between pointer and integer. Though it runs, it is revealing that the break code which checks for a comma is not functioning as the compiler warns. Why is it claiming this is a pointer? Why is it saying anything about an integer when I've deliberately cast k as a character? Thanks for any input. ------ Update: The problem was solved by: (a) changing the double quotes to single quotes (apostrophes) and (b) switching
if(k==",") break;
below the assignment. In order to match the file derived string with one defined in code I also had to modify it:
str2[j][strlen(str2[j]-1]='\0';
as there is something foreign added in the file transfer process. Thanks, and if there is a mark as solved button I couldn't find it:)
-
option 'explicit' for phpHi, Thanks for your reply and the code. I'm sorry but I didn't quite understand this: "Add one of the following Code to each Page you test / include in a config file." Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly? Thanks for any clarification:). Jeff
-
option 'explicit' for phpHi, I'm having major problems with erratic php behavior. I think it's something to do with the server, though I'm not sure. It is incomprehensible in a way that C++ or VB could never be: the same code will work and then not work even though no inputs or context have changed. I need to get a handle on this. A step in the right direction would be to get more information out of the server. Is there an "explicit" or "strict" option in php? I've searched for it here, and on the general Internet and haven't found it. I could try to explain the behavior but no one would believe me anyway. It is pretty much as if there were a "ghost in the machine" making arbitrary decisions as to when the code will work. Jeff
-
MySql not responding to queryHi, I will definitely look into classes in php as this will simplify a lot of the mechanics. Going back to a previous point about strings, basically I haven't seen that the return/enter key has any effect on processing. It seems to view it the same way whether it is line separated or not. Maybe on some systems it does but I haven't seen any evidence of it on this server. Thanks, Jeff
-
MySql not responding to queryHi, For some reason this text system ate the "br"s. I think I was supposed to use the <> s listed at the top of this text box. Sorry. Jeff
-
MySql not responding to queryQuick update, I continued working on this all today. I now have quite a bit up and running. Basically I just tried different code pieces I saw throughout the internet. Some worked and kept building on those. This is just intended to do the most rudimentary operations and does no useful work. For example the names entered into the table are hard coded -- of no practical use. And of course the conditionals redundantly test positive and negative. But the important thing is what it that it actually interacts with a database through php: Opens a connection Opens a database Deletes any existing table Creates a table Writes two rows of data to the table Prints out the first and last names from the two rows Closes the connection. (Actually it is only the last operation that I have not confirmed is working, but everything else definitely is.)
"; mysql_select_db($dbname) or die(mysql_error()); echo "Connected to Database "; $sql = "DROP TABLE IF EXISTS Persons "; $success=mysql_query($sql); if(!$success){echo" Table not deleted";} if($success){echo "Table deleted";} echo " "; $sql = "CREATE TABLE Persons ( FirstName varchar(15), LastName varchar(15), Age int )"; $success=mysql_query($sql); if(!$success){echo" Table not created";} if($success){echo "Table created";} echo " "; $success=mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('John', 'Peters', '18')"); if(!$success){echo" John Peters not added";} if($success){echo "John Peters added";} echo " "; $success=mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Mark', 'Waters', '62')"); if(!$success){echo" Mark Waters not added";} if($success){echo "Mark Waters added";} echo " "; $result = mysql_query("SELECT * FROM Persons") or die(mysql_error()); echo "Made it through Select From"; echo " >"; echo "Printing contents of array"; echo " "; while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo " ; } mysql_close($connection); if (!$connection) { echo "Connection closed"; } ?>
-
MySql not responding to queryHi, Well I think there is something odd happening on the server side. Just for the hell of it I tried putting the query directly into the statement like this:
mysql_query
(
"CREATE a;idsofvTABLE 'users'
('name' VARCHAR(20))",
$connection
);Rather than loading it into a string variable first. Lo and behold it generated a much anticipated error! Then I removed the garbage and no error occurred. I tried adding and removing the garbage several times and it gave expected behavior every time. Very exciting. But then it went back to the bad old ways and failed to give an error message upon garbage addition. There have been other instances of odd server behavior. Obviously people successfully run MySql databases from Godaddy so somehow they are working around this weirdness. I just have to figure out how. Jeff
-
MySql not responding to queryI've reprinted Luc's response here from the GDb forum. ______________________________________________________________ Hi Jeff, three suggestions: 1. CodeProject has a separate forum for MySQL; 2. I take it you are aware MySQL isn't SQL, the query language is somewhat different (so start every Google search with "MySQL") 3. there is a function that generates a textual description of the last problem. I recommend you test for success after every MySQL function call, and print the result of that function whenever a failure occurs. Here is an example (using PHP, where . is the string concatenation operator): $this->;Connection=mysql_connect($host, $username, $password); if (!$this->;Connection) { die("DB Error: Could not connect to $host: ".mysql_error()); } That should help you in understanding what is wrong where. ;) ___________________________________________________________________ Thanks for your response. 1)Has been addressed as you can see. 2)Yes,I'm aware they are different. 3)Okay I am getting connection information. Using, for example, this code:
$connection=mysql_connect($hostname, $username, $password) or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db($dbname) or die(mysql_error());
echo "Connected to Database";This does give back hints as to what went wrong if there is a failure in the connection. But the connections all seem to be fine. I'm wondering if is there something similar to the 'die' statement for queries. To my knowledge you can't use 'die' in that way. Right now the queries are clearly failing (in fact they can be garbage) yet I'm getting no feedback from MySql. Thanks, Jeff
-
MySql not responding to queryHi, I'm new to MySql and am just trying to get communicating with the database. Regrettably, perhaps, the database is set up on Godaddy, which has no support for MySql. The good news is that I was able to create the database on the server (shared hosting) and have been able to open a connection to it. Referring to the code here:
When the php code is called it prints out 'Connection established' and does not print 'Could not change into database'.
The bad news is that it does not seem to be responding to any queries.
Basically I can put garbage into any of the $sql statements here and MySql never seems to object. In fact I think it is ignoring everything.Basically I'm trying to get it to create a table in the database...but for now that's not even important, I'm really just trying to figure out why the system isn't even "trying" to understand the $sql statements I'm feeding it.
Is there some bit of syntax I'm not getting? But even if so, why isn't it throwing up any error messages?
In the code below, I can change, say TABLE to TABLE893hg, and no error message results.
$sql = "DROP TABLE IF EXISTS `users`";
$mysql_result=mysql_query( $sql, $connection );
echo('$mysql_result ');$sql = "CREATE TABLE `users`
(
`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20 ) NOT NULL,\`address\` VARCHAR(30) unsigned NOT NULL, PRIMARY KEY ( \`id\` ) )";
mysql_query( $sql, $connection );
$f_name="John Smith";
$f_address="BurlingtonVT";
$sql="INSERT INTO users (name, address)
values
('$f_name','$f_address')";echo($sql);
Maybe some of the parentheses aren't placed correctly or some other problem, but if it doesn't even tell me there is something wrong it's pretty hard to start finding the problem;)
Thanks for any insight.
Jeff
-
MySql not responding to query [modified]Hi, This has been reposted in MySql forum. Jeff
modified on Thursday, September 17, 2009 10:48 PM
-
Just trying to get simple app to run on the serverHi, As I've looked at the error it does show that at least it is recognizing where the pages should be found. In the error message below you can see that it shows the requested URL and then the location of the folder containing the ASP.NET app, which is correct. So it's definitely better than the "can't find server at..." error. It seems to be complaining about configuration data for the page. Unfortunately I don't know much about page configuration data, and a Google search didn't help much. Any ideas what might be ailing it?
HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid. Requested URL http://localhost:80/VS_Website1 Physical Path C:\inetpub\wwwroot\VS_Website1 Logon Method Not yet determined Logon User Not yet determined
Thanks, Jeff -
Just trying to get simple app to run on the serverHi, Yes, I followed the other "path" of our exchange and found your info for IIS 7.0 which made much more sense. It's a major UI difference between the two versions!! I found that "scraping" the build contents gave some strange results, so I included the containing folder and found that the IIS UI seemed to understand what was going on. This is consistent with your reply. So I've completed all of the steps including the creation of a new application pool and assigning to it the sample website (VS_Website1). This actually doesn't appear to work, at least not by using http://localhost/VS\_Website1 or http:\\localhost\VS_Website1 I get the 500.19 Internal Server Error. Also, I'm not sure I'm following the basic idea since this all seems to be leading back to hosting it on my own computer which I can already do. How does this relate to getting it onto the external server? I'll continue to read on in the article and see if I can see the thrust of what you're doing here.... Thanks, Jeff
-
Just trying to get simple app to run on the serverWow, that's a lot to take in. There appears to be a version difference, so I'm having some difficulty finding all of the screens shown in the example. Let me start with what you have written,
1. Published your web application from VS.
Can I use the files which result from a "build" instead of a "publish"?2. Copy the published folder in C:\initpub\wwwroot
Do you mean copy the published folder into the preexisting C:\inetpub\wwwroot file (I assume yes) or to create a new path called C:\initpub\wwwroot also, should I paste in just the contents of the program folder, or include the folder which wraps the files? __ I guess there is a version difference, because I'm getting hung on6. Right Click on that Folder > Properties 7. In Defult Tab, There is a Create Button. Click on It
The problem is there is no Properties option when I right click. In fact I can't find the Properties anywhere (normally this would be at the bottom of list upon right click). If I could find this functionality somewhere I would be able to follow along but so far..... I'll keep working on this. Jeff -
Just trying to get simple app to run on the serverHi, Okay I'll check that out. Thanks...
-
Just trying to get simple app to run on the serverHi, I'll check out those links in just a second.
Which OS are you using? In recent there are 3 IIS is used. IIS 5.1 (WinXP) , IIS 6.0 ( Win 2k3), IIS 7.0 (Vista Premium, Win Server 2008 )
I'm assuming IIS 7.0 because I'm running Vista. Also, as I mentioned in the other reply, there appears to be an issue because I'm running the Express version of the Visual Web Developer. I guess it's a Catch 22. I want to know if it is worth ponying up the dough for this thing. But it's hard to determine that if it won't let me upload the app to test. Jeff
-
Just trying to get simple app to run on the serverHi, Okay I see one of the problems I'm having is I'm using the Express edition. I just learned through the MSDN site that you can't publish the website without the full version. I'm wondering if maybe there is a way to work around this limitation or if it really is impossible to actually use the Express edition in a practical way. Thanks, Jeff