This is my c program below. Again everything works as expected up until the highlighted lines or the second for loop. When i run my program to
output the arrays contents i get bizarre numbers that are not correct.
# include <math.h>
# include <stdlib.h>
# include <stdio.h>
# include <time.h>int...
First, I get the string and I find the frequency of the every character. My struct is:
typedef struct huffman_tree{
char c;
int freq; //unsigned?
struct huffman_tree *left; // 0 (left)
struct huffman_tree *right; // 1 (right)
}huffman_tree;
I write this to create Huffman tree...
#include<stdio.h>
int main(){
char str[]="My first book";
char *a,*b,*c;
sscanf("%s %s %s",a,b,c);
printf("a=%s b=%s c=%s",a,b,c);
}
I want the output: a= My b=first and c=book. But it does not work, why?
Hello!
My homework is making a crossword.
I write a code like this:
do{
//code
printf("Please enter the coordinate and the word: \n");
scanf(" %c%d %s",&row2,&column2,word2);
if(row2=='E' && word2=="xit") exit(0);
//code
}while(count2!=10);
But this is...
Dear Forumers,Given a simulink model:
http://www.femm.info/Archives/contrib/images/TransientLoudspeaker/SimulinkOverview.png
I would like to implement fast code for it.I have no access to matlib or simulink at all, so I tried to implement the simulation in C code.
Code for the block...
I have recently come across a datasheet for a buck converter regulator that uses the terms "c code" and "No." for certain capacitors but when going to the manufacturer datasheets for these capacitors they make no reference to any "c code" or one single number for a capacitor. If anyone could...
Homework Statement
This is a question from the test i had today in which we had to look at certain C code segments and deduce which code part is missing in order for the program to do what we desire. Part b) was a short questionnaire to test our knowledge about c types and declarations.
Part a)...
Homework Statement
I need to write an Erdos-Renyi random graph, by using the adjacency matrix (or alternatively list) and calculate the fitness of the graph.
Definition: G(n, p) is a random graph with n vertices where each possible edge has probability p of existing.Homework Equations
The...
Hi, i wrote a code and annotated it but i have few problems with it. First it won't run on Visual Studio but it runs fine on repl.it online site which uses a C ide. Second, it seems wrong when i input
5
45 6 -4 8 3
It should print out 8 3 but for some reason it misses out on 3. Could you see...
Homework Statement
I am fairly new to C programming. I need to write a code that creates an array of max 300 numbers, ask the user to input the numbers and then print that array.
Homework Equations
3. The Attempt at a Solution [/B]
Here is my code
#include <stdio.h>
void main() {
int...
Homework Statement
Hi, I have a piece of code that I'm trying to comprehend but I don't understand some aspects. Here is that code:
#include <stdio.h>
/* function prototype declaration for FindSum */
void FindSum(int, int, int *);
int main(void)
{
int a=2, b=5, c=1, x=3, y=4, z=7;
/*...
Homework Statement
I'm using a PIC 16F877A microcontroller. An LDR and moisture sensor connect to the ADC. The main body of the code is ''void main'', and there is also a sub-code called "void light_the_led'' which is read inside the 'void main code'.
I cannot get access easily to hardware or...
I had an interview the other day and the lady was asking me about different ways to find whether there are any repeated elements in an array. At the end of the interview she told me to send her a code sample showing how to implement two of the ways we discussed. I thought that what I wrote was...
I need to write some c code that displays a counter value on four 7 segment displays. The number should increment by one every time a button is pushed. I cannot test this code as my home computer will not run Quartus 2 so I am working blind at the moment, but I would still like to ask some...
the following code
#include<stdio.h>
#include<stdlib.h>
int
main (int argc, char *argv[])
{
int* a;
*a=1;
return 0;
}
compiles ok, but throws "Segmentation fault (core dumped)" at runtime
why is that?
i'm working with gcc in ubuntu. I have been able to compile and run...
Hi,
I am trying to smooth a path defined in 2d by (x,y) which varies in time. I am using the Numerical Recipes 1d smoothing C code functions savgol() and convlv() to smooth x and y independently, which seem to do a pretty good job. However, while it seems to work, I was wondering if I should...
Hi guys, i am using the C language and have created the following function:
void counter (double c) {
FILE *fp;
char output[]="output.xls";
int n,p=0;
int r=0;
int i,j;
float x=0;
fp=fopen(output,"w");
fprintf(fp,"rmax\tnumber of particles within rmax\r\r\n");
for(n=1;n<=10;n++)...
Hi. I've been working on a finite-difference problem in differential equations. I was wondering if this code can be further optimized, perhaps eliminate some if statements or assignment statements. That is, what is the most efficient way to code this or is it already written in the most...
Homework Statement
I need to optimize this given code:
/* A struct used to compute averaged pixel value */
typedef struct {
int red;
int green;
int blue;
int num;
} pixel_sum;
/* Compute min and max of two integers, respectively */
static int min(int a, int b) { return (a < b ...
Homework Statement
I need to optimize this given code that rotates an image 90 degrees so it runs at least three times faster:
void naive_rotate(int dim, pixel *src, pixel *dst)
{
int i, j;
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
dst[RIDX(dim-1-j, i, dim)] =...
Homework Statement
I want to read each line separately in a char array from a text file. As yet, the best I could do is to read the entire file in a single char array. How can I read each line in a separate array?
Homework Equations
The Attempt at a Solution
#include <stdio.h>...
Im using the c programming language and just wanted to ask a quick question. In a while loop how do you make the program terminate by printing a value or a message here's my code
while ((fabs(func(x))>epsilon))
{
if(deriv(x)==0) {
print the last value of x and stop the whole program}
else {...
my attempt is
(this is c programming)
My output is really different. It gives the answer but not a detailed solution as the output above.
Pls help me I really don't know how to show the long method :frown:
Hey
I am having some issues with my C code.
What it should do is calculate the output speed when a gear combination is used. It loops to find all combinations for 4 gears from 1 to 42, but can be changed.
2 things i can't get working
- IF STATEMENT - i want it to only show...
Hi,
I tried to assign inputs to a particular output and I've got some funny results. In this code
ive change the value of rpm to into the address of arrays that I've set. The adress correspond to the delay time for spark to occur.
Heres my c code :
#include <stdio.h>
void main()...
Homework Statement http://www2.warwick.ac.uk/fac/sci/physics/teach/module_home/px270/projects/c4s_projects07.pdf
it's the first example
Homework Equations
see aboveThe Attempt at a Solution
right i shouldn't have any probs with the programming but i need to understand the calcs that are put...
have the following MIPS 32 asm code:
Assuming B is an array of 10 words whose base address is in register $s0, andvariable c and i are in $s1 and $s2, respectively. What is the C statement implemented by the below MIPS assembly code?
add $t0, $s2, $s2
add $t0, $t0, $t0
lw $t1, 0($s0)
lw...
I am starting a programing class for scientists and engineers at the end of the month. I wanted to brush up on my C. I used to compile C programs with Visual Studio, but now that no longer seems to work. Even simple example programs in the book generate a litiney of compile errors in Visual...
Hi, I have a problem to code this:
Image that you have the following file presenting the following decimal values:
2 A 40.0
115.00 1.02842 5.944 10.0528 -1.656
115.00 1.01911 4.678 10.0528 177.078
11 6 100.0
115.00 1.01530 2.392 2.9097 11.933
115.00 1.00338...
Hi, I am trying to write a loop that will check a users input to be between a certain numeric range in C. The thing is, I expect the person to enter a number, not a character.
When the person enters a character, the loop becomes infinite. Thats the problem.
If you look at example source...