|
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..
|
|
|
|
|
|
This has nothing to do with C/C++ programming.
|
|
|
|
|
Not really a question for a programming site but as it's in my area. You configure the LM317T as a current source you can neglect the voltage totally. There is a formula for trickle charge rate of NiMh an online calculator is here Rechargeable battery charging time and mA current calculator | Convert to units and culinary measures.[^]
For a 2000maH stack maximum trickle charge rate is 66mA which is well within range of your solar panels. You can't charge any faster using a simple LM317T circuit otherwise you will damage the batteries.
Finally the circuit is shown here (second one with the solar panels)
Ni-Cad Battery Charger with LM317 - Jose Pino's Projects and Tidbits.[^]
The 22 Ohms on the circuit will give you 56mA of trickle charge .. if you want exact max 66mA you need 19 Ohm 1/2 Watt resistor.
The diode protect (1N4001) protects the solar panels when they aren't in sunlight
You want a more advanced charger go to a proper electronics hobby site and not here
In vino veritas
|
|
|
|
|
It is site driving spam.
The text has been copied from a 2014 StackExchange post and extended with a link to the distributor.
|
|
|
|
|
Haha I get it now .. will ignore in future.
In vino veritas
|
|
|
|
|
Message-passing on the binary erasure channel
Code word =[1 0 0 1 0 1]
Y= [1 0 0 x x 1]
Procedure DECODE(Y)
I= 0
For i= 1 :n do
Mi=yi
end for
repeat
for j= 1 :m do
for all i ∈Bj do
if all messages into check j other than M i are known then
end if
end for
end for
for i= 1 :n do
if Mi= ‘unknown’then
Mi=Ej,i
end if
end if
end for
if all Mi known or I =Imax then
Finished
else
I=I+ 1
end if
until Finished
end procedure
|
|
|
|
|
|
I am working LDPC encoding and decoding for mini project work. With my effort i have completed LDPC encoding but struggling with LDPC decoding.
Message-passing on the binary erasure channel
Code word =[1 0 0 1 0 1]
Y= [1 0 0 x x 1]
|
|
|
|
|
Can anyone help me in writing C languageLDPC Decoding:Looking for logic using algorithm.-algo-png for decoding procedure. Please give me logic.
|
|
|
|
|
|
I have already know that in Wikipedia, Low-density parity-check code is given but not the logic. I have gone through all the theory parts. Thanks for your logic.
|
|
|
|
|
If you have gone thru the problem them you should have already realized, you can't decode anything until you first sort out the type of encoding. LDPC isn't one thing it is a verbose description of any number of schemes it is an NP-complete code problem. So you may have read the wikipedia article but you don't understand it.
Effectively you just asked us to help us build a vehicle and we don't know if it's a car, boat, truck, train, hovercraft or plane.
Look all I can do is point you at
GitHub - jontio/LDPC-4Qt: Forward Error Correction using LDPC codes with Qt C++[^]
As it says the code on there is too slow and totally useless for any sort of real world use it will just get you to understand LDPC codes.
In vino veritas
|
|
|
|