|
Thank you CPallini
my name is Calin Negru, I also post on GameDev.net
modified 20-Jun-20 3:14am.
|
|
|
|
|
|
void main()
{char name[50],came[50];int i;
gets(name);
gets(came);
for(i=0;name[i]||came[i];i++)
{int d=name[i]-came[i];
if(d==0)
return printf("Equal");
else return printf("Unequal");
}
}
|
|
|
|
|
Using return where you do, exits the current function you are in, in this case it is main(). So you are exiting the program when you call return.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
|
<pre>#include<stdio.h>
void main()
{char name[40];
printf("Enter the string:");
gets(name);
char ch = ' ';
int i,count=0;
for(i=0;name[i];i++)
{if(name[i]==' ')
count++;
}
printf("Number of words is %d",(count)+1);
}</pre>
-- modified 31-May-20 15:08pm.
|
|
|
|
|
This is something I hate, but it's idiomatic. A C string ends with the character NUL, whose ASCII value is 0, which is equivalent to false . So the loop ends when the character NUL (usually written as '\0' ) is encountered. The check is equivalent to
name[i] != '\0'
but some people hate typing so much that they write this kind of thing.
modified 31-May-20 15:49pm.
|
|
|
|
|
The for statement breaks down as three individual expressions:
for(set; while; do) :
Note that any of these expressions (or indeed all of them) may be blank.
In your code the expression in the while part is name[i] , which means while name[i] is true , or rather while name[i] is not equal to zero . Strings in C are (or should be) terminated with a zero character (NULL), so the expression will be true as long as the character in question is not the terminating NULL.
|
|
|
|
|
Can you pass an entry from the middle of the array as argument to a function?
void AFunction(int * ArrayItem, int size)
{
}
int TestArray[5];
AFunction(&TestArray[3], 5);
modified 31-May-20 15:28pm.
|
|
|
|
|
Sure, as a pointer to that element (&array[i] ) or as a reference (array[i] ). This is assuming you want access to the actual element, not a copy. If it's an array of int , the receiving arguments would have the types int* and int& , respectively.
modified 31-May-20 15:46pm.
|
|
|
|
|
What are the constraints? do you have access to other elements in the array in this situation? the function body in my example code is not defined because I`m not certain how it should look like.
|
|
|
|
|
No, this only gives you access to the element that you pass in. If you want access to all of them, pass the array itself (I seem to remember a previous thread about how to do that) and use the index operator.
modified 31-May-20 17:45pm.
|
|
|
|
|
|
Using C/C++ code, How to read a text file (approx size 100GB) line by line from a remote machine in LAN directly without downloading or copying the file
|
|
|
|
|
You would need a client application on the remote system, or remote access, to read the file and pass the data to your program.
|
|
|
|
|
With a typical client/server application, your TCP server runs on the remote machine, waiting for 'gimme next line' command from the client. On command reception, it reads the line and answers to the client with the read line content.
|
|
|
|
|
is the machine doing the reading on the same network as the machine with the file? If so, just use a UNC, something like:
\\machine\folder\...\file.ext
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Nice.
|
|
|
|
|
I am working with embedded C and sometimes I compile with Eclipse/GCC and sometimes with STMicroelectronics System Workbench. In my code there are a lot of nested macros and I think it would be great to display the expanded macro value as a comment right after the macro (note: only the macros without parameters). So I was thinking of having a post-build .exe-file/script that takes the result from the precompiler and puts it back into the source code as comments after the macros. As an alternative, I could have a pre-build .exe-file/script that executes the pre-compiler (meaning it will be executed twice for each compile) and then modifies the source code. I feel fairly confident about writing the .exe-file/script, but I have no idea how to execute the precompiler "on demand" or how to view the results of it. Could someone please provide some guidelines on how to achieve this? I know pretty much nothing about makefiles, precompilers, compilers, etc, so please feel free to formulate your answers in this thread in the way you would communicate with a beginner programmer.
|
|
|
|
|
See Overall Options (Using the GNU Compiler Collection (GCC))[^]. The -E option of gcc allows you to stop the build after running the preprocessor. The out put will be the expanded source. But be aware that this will include the expansions of all input from included headers so may well be quite extensive. If you run a few samples you should be able to see how to get to the source that you are interested in.
|
|
|
|
|
I just tried it, but it seems I need to reference the macros in order to get the expanded values. Most of my macros are never referenced in the project I would like to generate the explanatory comments in, they are just defined in a (shared) .h-file.
|
|
|
|
|
If they are not used then the preprocessor will ignore them. Macro expansion happens at the reference, not at the definition. You may need to create some dummy file to get the expansions. A better idea would be to write proper documentation comments so they can be seen by anyone looking at the definitions. And I think that may also make them visible through intellisense.
|
|
|
|
|
I am creating an application using c# winform to create and mount ISO files like wincdemu. I am able to create the ISO file and mount it like a local drive. I want to mount the image with disc type CD-ROM/DVD-ROM. I am using AttachVirtualDisk() to mount the image.
Is there any API/library support to mount the image with disc type CD-ROM/CD-R/CD-RW/DVD-ROM/DVD-RAM etc. ?
I appreciate any advice.
|
|
|
|
|
You might be better off asking in the C# forum.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Hello,
We use a third party library for our grids. Each grid cell has a style, one member of which is the font:
class CLibStyle
{
[...]
CLibFont m_pFont;
[...]
};
During deserialization serialization in the library methods, the font is managed as follows:
ar >> m_pFont;
For our part, we deserialize the styles line by line, column by column, then storing them in a map to use them later:
CLibStyle * pStyle = NULL;
for (int nNumRow = 0; nNumRow ++; nNumRow <nNbRow)
for (int nNumCol = 0; nNumCol ++; nNumCol <nNbCol)
{
pStyle = new CLibStyle();
pStyle->Serialize(ar);
mapStyle->AddTail(pStyle);
}
So far it's very basic but this is where we have a big problem because it happens that this deserialization, as simple as it is, allocates pointers m_pFont on the same memory areas from one loop to another. With the same archive file, this problem does not necessarily arise depending on whether you are in Debug or in Release, or even differs from one PC to another.
Afterwards, we inevitably have problems even if the pointers are destroyed ...
Any ideas for ensuring that pointers are not allocated on the same memory range?
Thanks a lot for your help.
modified 25-May-20 3:49am.
|
|
|
|