|
I'm still working on it. now calculating sample 250 of 100000
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Having the sample count already specified implies this is a homework question, but I'll try to give as many hints as I can without ruining it for your learning...
1/ To start with, this isn't a C specific question, but there's nothing stopping you doing this in C. You could do it in fortran, c#; heck, I'd probably recommend using excel...
2/ Your initial problem is solving the equation on pen and paper.
(Yes, I know you have a thing that varies - remember your algebra)
volts = current * resistance
power = current * volts
current = volts / resistance.
I'd suggest excel to start with, or a simple MFC dialog application with a box you type in a user supplied resistance value, and then spit out the results you care about to test your equation.
4/ Now move on to the second part of the question, the varying resistor.
4a/ What is the probability curve? Even if you assume it's flat, you should document that assumption. Why is it varying? If it's a toddler playing with a knob, it may be a guaussing distribution. The point is that it's not specified, so you either have to ask, or at least spell out your assumption.
4b/ Look up Monte Carlo Simulation - I bet it's what you've been taught. Run your function 100000 times with a random number between 200 and 600 and pop the results into a huge table.
4c/ Whether you write them to a text file, and import that into excel, or add a pretty graphic control (we have them here on CP) is up to you.
Good luck,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
i am having a grid control in which i did some masking for 10 characters. But if i enter some less characters then it appends underscore character to the end which i dont need. Please provide comments.
|
|
|
|
|
show us how your are masking your string
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
The short answer: Just remove the characters that you don't need.
The answer: Read the sticky post at the top of this forum. Provide more information that will let us give you a helpful answer.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
pandit84 wrote: i am having a grid control in which i did some masking for 10 characters. But if i enter some less characters then it appends underscore character to the end which i dont need. Please provide comments.
Comment no.1: "Uh, what an interesting post".
Comment no.2: "Apparently, the grid control doesn't fit you needs".
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
When I try to compile my code I get this error message:
@: gcc -o hw3 hw3.c
hw3.c: In function `main':
hw3.c:20: parse error before `char'
hw3.c:31: `buff' undeclared (first use in this function)
hw3.c:31: (Each undeclared identifier is reported only once
hw3.c:31: for each function it appears in.)
The error occurs because of my if statement.
When I place the if statement after the char declaration it works, also when I remove the if statement it compiles and works fine.
if(argc == 1){
printf("Error: hw3 <buffersize>");
return 1;
}
Also for a plain "if(){}" as well.
How do I get around this?
#include
#include
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char * argv[])
{
int fileread, filewrite;
ssize_t nread, nwrite;
if(argc == 1){
printf("Error: hw3 <buffersize>");
return 1;
}
char buff[ (int)argv[2] ];
fileread = open("128kB.bmp", O_RDONLY);
filewrite = creat("copy.bmp", O_WRONLY);
while(1)
{
nread = read(fileread, buff, sizeof(buff) );
if (nread == 0) break;
nwrite = write(filewrite, buff, sizeof(buff) - 1 );
}
close(fileread);
close(filewrite);
return 0;
}</buffersize></stdio.h></fcntl.h>
I am using a putty terminal connected to a unix machine.
|
|
|
|
|
Endomlic wrote: When I place the if statement after the char declaration it works
Then, why not do it that way?
I reckon good old C compilers expect you to declare all the variables used in a a function at the very beginning of the function block and not anywhere in between. I also think that more recent versions of C compilers allow this.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
If I declare the char beforehand then I can't use the if statement as intended.
I need to see if they actually entered a buffer size, if not then the program will crash with the wrong error message I want displayed.
That's where the if statement comes in. The if will break the program if they do not specify a buffer size. and if they do then it will be used as the char buff array size.
How else can I declare a char buffer size and change it after the if?
|
|
|
|
|
Endomlic wrote: How else can I declare a char buffer size and change it after the if?
Declaring it as a pointer variable prior to the if statement, and doing dynamic memory allocation later sounds like a viable option?
Or may be switch to a more recent version of the compiler that supports declaring variables anywhere.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Endomlic wrote: char buff[ (int)argv[2] ];
1. You are trying to create buffer dynamically. -Without specifying a constant value for memory allocation. It requires you to use "new".
2. Use atoi to convert argv[2] to an int value. You cannot just cast like that.
Example:
char* buff = new char[atoi(argv[2])];
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
VuNic wrote: char* buff = new char[atoi(argv[2])];
Dynamic buffer? "new"?
It is a C program and I see the issue is different. The OP is attempting to do something that his version of compiler doesn't support. I might be wrong though...
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Oops! "malloc" then. The idea is same in C right? How will it allow you to create buffers without knowing the size? But I'm not sure. Formatted C:\! from my brain. quite a while before
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
yea, how do I do it using malloc
|
|
|
|
|
char * buff = (char*)malloc(atoi(argv[2]));
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
I've tried that, but it acts as if it's not assigning buff with a size. in other words it's not working.
|
|
|
|
|
Endomlic wrote: but it acts as if it's not assigning buff with a size. in other words it's not working.
Are you really passing the Command-line argument? I think you are not. Command line args start from 0. If you are trying to mean the first argument, You must use argv[1] and not argv[2]. argv[0] the refers to the program name. Just try the below code to test how it allocates memory dynamically.
char size[]="10";
char * chBuff = (char*)malloc(sizeof(char)*atoi(size));
strcpy(chBuff,"TestMail");
for(int i=0;i<8;i++)
{
printf("%c",chBuff[i]);
}
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
VuNic wrote: How will it allow you to create buffers without knowing the size?
Some versions of the GNU C compilers allocate memory equivalent to the size of a medium grapefruit and hope for the best when the size requirement isn't exactly known.
OK, you know it's malloc, of course. Plus, there was the other problem which I stated in my reply to the OP.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Yay I got it to work!
It was
char* buff;
if statement;
buff = (char*) malloc( sizeof(char) * atoi( argv[1] ) );
Apparently I had to use argv 1 instead of 2.
I guess in gcc argv 0 is the program name.
Thanks to you guys for all the help!!
|
|
|
|
|
I figured it out. Took few minutes to type this[^]. lol that's great you got it!
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
I guess in any C program argv[0] is the program name...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Endomlic wrote: I guess in gcc argv 0 is the program name.
Not just in gcc, it's the same everywhere. good night!
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
I missed this one.
Thanks to an anonymous report (or 'signalation?' ) it is now in the list it deserves...[^]
Welcome again in the CP's memorable quotes page, Rajesh.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|