|
|
Can I ask do you actually know how to program in C at all?
With your last question about tanh and now this I am really suspecting not or you are a student and this is homework for like a communications unit.
All you have to do is translate that text to code (start with pseudocode if you like).
Here let me do step 1 and solve c4 it's 1 line of C code
if (c3^1^c6 == 0) c4 = 1; else c4 = 0;
That assumes c3,c4,c6 etc are int's or something I can run the logical operator on but you haven't even told us that detail but you want us to write some code. For now lets just treat it as pseudocode.
So code written that is the solution to step 1, we have c4 evaluated.
Now you try Step 2 it is a simple shuffle of c4 from above back into the nodes but we don't know what you have the data in. So how about you have a crack at writing the code and show us. Even if it's not working I can at least see how you have the nodes setup. I don't even care about the types for now just write the variables c4 is adjusting.
Lets give you Step 3.
if (1^c2^c3^c4 == 0) c1 = 1; else c1 = 0;
Step 4 is another simple shuffle just needs some code which will be similar to Step 2 and you then have pseudocode to the entire problem.
In vino veritas
modified 27-Jun-17 21:19pm.
|
|
|
|
|
Thanks leon de boer. As per your guidelines, i will start writing the codes.
|
|
|
|
|
Hi,
First of all genuine thanks to all that contributed to my previous queery. It was really helpful, and moved things along.
I wrote a method: MkRvaPrt() that takes an rva, and maps it successfully to the file location, rather than to the memory location where the object would be after using LoadLibrary();
Sections in a PE File are used where a block of binary data is mapped to a file location other than the offset in the file.
What the MkRvaPtr() function does is, it checks whether the virtual address is within the ranges of any of the Section Headers, (irrespective of name), and, if so calculates the adjustment, and returns a pointer into the file. If it does not point into a section, it returns the rva offset into the File.
This all works smooth, but sets the stage to several questions.:-
Sometimes, the rva found, already points at the required data, at other occasions, it has to be converted with MkRvaPtr.
e.g.:
I need to use MkRvaPtr to get the name of each Import Module, but the list of "PtrsToImportNames" needs no such translation.
Does this table consist of relative offsets to itself? If so, How was I to know!
Kind Regards,
Bram van Kampen
modified 26-Jun-17 21:10pm.
|
|
|
|
|
Hi, I want to fill out a char array with space.
like:
memset(msgArray, '*', 100);
but '*' should be a Space key.
|
|
|
|
|
memset(msgArray, ' ', 100);
memset(msgArray, #32, 100);
or a myriad of others
In vino veritas
|
|
|
|
|
Thanks, ' ' and 32 work.
in fact, it's snprintf() reason. snprintf seems fill out the gap in a string with '\0'.
modified 25-Jun-17 10:06am.
|
|
|
|
|
I find this question a bit mysterious, if you had tried the obvious thing it just should have worked.
The "obvious thing" is:
focusdoit wrote: '*' should be a Space key. .. literally just replace '*' by ' '.
|
|
|
|
|
in fact, it's snprintf() reason. snprintf seems fill out the gap in a string with '\0'.
the code like:
memset (msgArray, ' ', 100);
snprintf (msgArray, 2, "%d", 1);
snprintf (messageArray+10, 33, "%s", "main");
I assume the string should output like:
1 main
but debugged it. it is : 1,\0, ' ', ' ', .. main, \0, ..
|
|
|
|
|
Well snprintf terminates its output with a \0, which is typically useful (it would be a bit dangerous if it didn't), you can just overwrite that \0 with a space.
|
|
|
|
|
Here's the prototype for the function :
int _snprintf( char *buffer, size_t count, const char *format, ... );
I usually use it like this :
const size_t bufferSize = 127
char buffer[bufferSize+1] = {0};
_snprintf( buffer, bufferSize, "%3d %s", index, yourString );
You can combine the _snprintf calls into one since they are going into the same memory buffer.
|
|
|
|
|
That is because you are doing it all wrong you either join them all up in one sequence or move the first pointer along
They are designed to be used a completely different way
Single line:
snprintf (msgArray, sizeof(msgArray),"%d%s", 1,"main");
Concat sequence (with buffer safety):
char *cur = &msgArray[0];
char *end = &msgArray[sizeof(msgArray)-1];
cur += snprintf(cur, end-cur, "%d", 1);
snprintf(cur, end-cur, "%s", "main");
In vino veritas
|
|
|
|
|
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules:
A. If the average score is 90% or more, the grade is A.
B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B.
and it continues...
The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results.
This is what I have so far but it will not run for me. I am not allowed to use global declarations
|
|
|
|
|
You don't show what you have so far, so we can't really give you any explicit help.
But ... if you can't use global declarations, then you need to use local variables and parameter passing. That means you write your functions to accept the data they are to work on, and return values to the caller.
For example:
int sum (int* data, int count)
{
int i;
int total = 0;
for (i = 0; i < count; i++)
{
total += *data++;
}
return total;
}
...
int main()
{
int result;
int data[100];
int i;
for (i = 0; i < 5; i++)
{
data[i] = i + 1;
}
result = sum(data, 5);
printf("%u\n", result);
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This requires to use variables to hold the scores and the grade. If you are not allowed to use global variables you must declare them in your main() function and pass them to the functions:
int main()
{
int grade;
int score1, score2, score2;
ReadScores(&score1, &score2, &score3);
grade = GetGrade(score1, score2, score3);
PrintGrade(grade);
return 0;
}
hoangtrungl wrote: The program's main is to contain only call statements. I would read that in the sense of that it should not contain any operations but that variable declarations, assignment, and the mandatory return statement are allowed.
[EDIT]
After thinking about it a while I found a solution that does not use any variables in main() :
int main()
{
PrintGrade(GetGrade(ReadScores()));
return 0;
}
Then ReadScores() must return a structure containing the data (which may be optionally dynamically allocated) that is passed to GetGrade() (which can free allocated memory) which returns the grade that is passed to the Print() function.
[/EDIT]
modified 23-Jun-17 5:49am.
|
|
|
|
|
hoangtrungl wrote:
This is what I have so far...
"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
|
|
|
|
|
Hmm
Ah, it is that time of the year again. This looks suspiciously like an examination project. There are various reasons why this forum does not do these. For one, most people on this forum have already passed their exams, while many others earned their feathers trough self study and hard graft. Furthermore we would not like to contribute to the creation of qualified software engineers who mis the basic concepts.(as you seem to do).
You don't actually show what you have. (maybe you don't know how to, if so, follow the posting guidelines on this site.)
Show me yours, and I'll show you Mine.
Bram van Kampen
|
|
|
|
|
Dear Programmers,
I converted a linux code to vc++ MFC app(VS2012), compiler generating this error on compilation:-
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(39): error C2039: 'fclose' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(39): error C2873: 'fclose' : symbol cannot be used in a using-declaration.
Though have tried several setting changes, but this error is upsetting.
Any help would be highly appreciated.
-Pankaj
|
|
|
|
|
This may occur when the source file is compiled as C.
If it is a plain C file (.c) you should not include cstdio but stdio.h.
If it is a C++ file (or should be compiled as such), set the appropriate option in the project settings (I have no VS21012 here but it should be at "C/C++ - Advanced" - "Compile As") to compile all files as C++, or rename source files to .cpp.
|
|
|
|
|
Dear
I have done it several times, but same errors are getting produced. Problem is not with code...problem is if vc++ 2012 compiler IDE...
Am I missing some library/ switch..?
-Pankaj
|
|
|
|
|
I can't really help without knowing what you are doing and do not have VS2012 here.
But this should compile (console project with pre-compiled headers):
#include "stdafx.h"
#include <cstdio>
int _tmain(int argc, _TCHAR* argv[])
{
FILE *f = fopen(_T("test"), _T("r"));
fclose(f);
return 0;
}
|
|
|
|
|
|
Dear programmer,
Code does not have any issue...VS 2012 IDE setting has...
Even I posted same problem in several boards..a programmer suggested that I should make a simple program on Visual C++ 2012 IDE, with <cstdio>. I made a simple app with only <cstdio>..(library/header...namespace as documentation says of microsoft). Again same error on compilation...
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cstdio(39): error C2039: 'fclose' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cstdio(39): error C2873: 'fclose' : symbol cannot be used in a using-declaration
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========..
Am i missing some setting..?
-Pankaj
|
|
|
|
|
I used VC++ 2008...there is not as much fussy issue, as VC++ 2012 is producing(useless hurdles)....program itself has complex logic...
Issue is closed..I changed environmnt vc++ 2008..
|
|
|
|
|
|