473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Code works in Visual C++ Express Edition, but fails by Miracle C

I am a student at University of Phoenix and required to use the Miracle C compiler. I recently completed an assignment by using seperate functions to populate arrays of character strings, which worked well when built using Visual C++ Express Edition 2005. The problem was that using Miracle C to compile/build/execute the same source, creates issues. Here are some excerpts from my code:

// Function to populate the array of strings
int getStores(char *storeNames)
{
int storeNameIndex = 0;

storeNameIndex = MAX_STORE_NAME_LENGTH * 0;
sprintf(&(storeNames[storeNameIndex]),"Del Mar\0");
...
storeNameIndex = MAX_STORE_NAME_LENGTH * 2;
sprintf(&(storeNames[storeNameIndex]),"La Jolla\0");
}

// Portion of main function that iterates through and prints the store names:

/* Print the Store Name, Purchase Amount, and the Tax Amount */
printf("\t%s\t$%.2f\n", &(storeNames[storeNameIndex]), taxAmount);

The problem is that on every iteration the output is La Jolla. Through debugging I was able to establish that the array was populated correctly in the context of the function, but then seems to be corrupted as control is passed from the function back to main. Does anyone reading know of outstanding issues with Miracle C around memroy management or is Visual C++ Express just too forgiving of my poorly written code???

Thanks for any insite!!

-Dave
Jul 21 '07 #1
1 1762
weaknessforcats
9,208 Expert Mod 8TB
This code:
int getStores(char *storeNames)
{
etc...
shows storeNames as a pointer to a single char.

The assumption is that there is an array at that address.

So, if you need an array of strings, you need an array of char* where each char* has memory allocated for a string. Like a 2D array. I would have expected an argument like:

Expand|Select|Wrap|Line Numbers
  1. int getStores(char **storeNames)
  2. {
  3. etc...
  4.  

Also, this code:
storeNameIndex = MAX_STORE_NAME_LENGTH * 0;
will always give 0 as the answer.
Jul 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: clintonG | last post by:
Visual C# 2005 Express Edition is a simple, lightweight, integrated development environment designed for beginning programmers and non-professional developers interested in building Windows Forms,...
6
by: John Dalberg | last post by:
I don't know how much Microsoft is planning to price Visual Web Developer Express Edition. I heard rumors from free to $100. In my opinion I think it should make it free. The reason is to attract...
4
by: Andrew Robinson | last post by:
My main dev machine has WinXp and VS2005 (pro). 1. I need to install VWD Express Edition so that I can do some instruction on this. Any issues with both on the same machine. Installation order?...
2
by: Progman | last post by:
I have Visual Studio 2005 Standard edition. Is ti the same thing as the Express edition or Standard is more?
9
by: Martijn Mulder | last post by:
Hi group, It is tempting to jump into .NET programming, especially C# in my case. But I have no idea what the realm is of code based on the CLR. Please inform me of the following: -what...
6
by: Simon Brown | last post by:
Hi, I am considering buying Visual Studio Standard Edition and have these questions about the VC++ incuded. Could you also, to help me know the diffrene in capablility, answer the same questions...
1
by: Ruth | last post by:
Which edition of Visual Studio do I have? "About" says that I have Visual Studio 8.0.5.0727.42: is this the professional, express, or enterprise edition? I do not believe it is the Team edition....
1
by: Ruth | last post by:
Which edition of Visual Studio do I have? "About" says that I have Visual Studio 8.0.5.0727.42: is this the professional, express, or enterprise edition? I do not believe it is the Team edition....
21
by: Goofy | last post by:
I see that the code behind is now a partial class. So where is the code associated with the server controls declaration etc ? Is this generated on the fly now, or am I missing something ? --...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.