C/C++ :: Vector Outputs Alien Language?
Oct 19, 2014
Program:I have 2 arrays: 1 for the correct answers to a quiz, 1 for the user. I then have a vector to hold the incorrect answers.
It keeps outputting what looks like alt characters, why.
Here is the code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
const char a1[]={'a','d','b','b','c','b','a','b','c','d','a','c','d','b','d','c','c','a','d','b'};
char a2[20];
int i=0;
int incorrect=0;
[code].....
View 1 Replies
ADVERTISEMENT
Oct 19, 2014
Program: I have 2 arrays: 1 for the correct answers to a quiz, 1 for the user. I then have a vector to hold the incorrect answers. It keeps outputting what looks like alt characters, why.
Here is the code:
#include <iostream>
#include <vector>
using namespace std;
int main()
[Code] .....
View 2 Replies
View Related
Oct 3, 2013
i'm student in computing science , i want to specialize in IT security and the first step i think is to know how to program a virus and understand how it works and how to stop it now i'm just a beginner I look for a way forward , i need some tips where can i begin? What are the basics of IT security? What programming language should I learn?
View 3 Replies
View Related
Jun 15, 2013
Q. In context of C language syntax checking, which of the following can be modeled using Finite Automata?
(A) Detecting proper termination of an instruction.
(B) Detecting balance of parentheses.
(C) Detecting initialization of a variable.
(D) None of the above.
View 4 Replies
View Related
Dec 18, 2013
I have to communicate between two laptops using USB-to-Serial adapter. I have written 2 programs one for sending and another for receiving. Programs were written in both C and C# programming languages.
Using C language: I am able to successfully communicate using C-Programs mentioned below. But the problem is speed. It takes around 1 hour(60min) for just to pass 150MB. improving the performance of this programs...I also mention some comments along with programs for self understanding.Sender File on laptop with serial port :
Code:
#include <stdio.h>
#include <bios.h>
#include <conio.h>
}
[code]....
The above 4 programs behaves as, sender send a character and receives an ack for every character. I have followed this approach, bcoz other approaches were not working fine (in the sense the complete data is not sent, the amount of data sent is not judgeable, bcoz it will different every tym). when i used this approach it worked fine.
View 6 Replies
View Related
Jan 25, 2013
Have a program which given a C source code file, gives back RAW MACHINE CODE, which means it doesn't have to be a executable on his own.
Like:
Given a example function for C:
int stdcall Function(void)
{
return 0;
}
Gives back the Machine Code for the Example Function.
It doesn't need to be actual C code, it can also be like:
type int
return 0
Or also it can be a straight assembly-to-machine-code compiler.
Is there any Library? Or even a external tool I can look into?
View 4 Replies
View Related
Sep 6, 2013
how to open an audio file using c. write a code to open an audio file.
View 2 Replies
View Related
Nov 15, 2013
The goal of my program is to convert a decmial number to a binary number.First, the program gets an input to an array of chars, and the function translate_dec_bin converts this array to a decimal number through the strtoul function.The problem is that my program prints the binary number with an additional "0".For exmaple, for the input 1 - the program prints 01 instead of 1, for the input 3 - the program prints 011 instead of 11.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 20
void translate_dec_bin(char s[]){
char st[sizeof(unsigned)*20] = { 0 };
}
[code]....
View 2 Replies
View Related
Mar 13, 2014
I have a problem about compiler.I want to write a simple compiler for a language.
stm -> id := expr
| print expr
| if expr then stm
| while expr do stm
| begin opt_stmts end
[Code] .....
I guess I should create main.c to convert source code.Also,I should create a source.c to write a example program that is relevant with above grammar.
View 1 Replies
View Related
Sep 27, 2014
I have a program that reads a text file and then outputs the corresponding transition table according to the regular expression given in the text file. The first line that is read by the code contains the transition table. The subsequent lines of the text files include the strings. I want my code to read the strings in the subsequent lines of the text file and tell me whether the string is accepted or not by the language. Basically, what my code does is that it translates the regular expression to an NFA and then, it translates the NFA to a DFA and then it builds a transition table according to the language.
I have included a special library in my code and I compiled my code from the command line using the following command:
gcc -o lalab lalab.c -lncurses
then, I just run the program like this:
./lalab
Another problem that I have is that my code does not handle the empty transitions, so the program should output a corresponding result when it is fed a regular expression such as a|e. The alphabet of the language is made of {a, b, e} e is the empty transition. The text file that the program reads from includes a regular expression in its first line and strings to be accepted or not in the following lines. Given an input file like this:
(a|b)*a
aaaa
aba
bba
ab
bbb
:frown:
The code should produce an output like this:
yes
yes
yes
yes
no
no
Code:
#include<stdio.h>
#include<conio.h>
#define MAX 20
//=========================================================
struct nfa_state {
int a, b, eps1, eps2;
}NFA[20];
[Code] .....
View 8 Replies
View Related
Nov 25, 2012
Running c in jgrasp.. i am getting error has gcc not found.
View 4 Replies
View Related
Apr 25, 2013
a few pointers in building an assembler in C for a 68hc11 micro controller I'm struggling on a way to convert the assembly language in a txt file to s19 format.
View 1 Replies
View Related
Dec 28, 2011
I have a project C# and i want to build it to .dll for use in ASP.Net project . Any way to do it. It look like my attachments image .
View 1 Replies
View Related
Jan 21, 2013
how to create a symbol table for an assembly language and high level language program in c++
View 1 Replies
View Related
Sep 25, 2013
TheC language program environment does nothing to prevent buffer overflows ..... is there any pros to the obvious cons of this?
View 3 Replies
View Related
Jan 21, 2013
How to create a symbol table for an assembly language and high level language in c++?
View 1 Replies
View Related
Jun 25, 2013
It is getting more and more annoying, everytime i progress the next hurdle is just bigger. The problem is i want to calculate inverse of a matrix but using .inv gives a matrix full of -1.#QNAN values so i decided to write one my self
a function which returns the inverse matrix but something strange happens.
when i debug through the function code it works well and check the matrix that will be returned and the elements are correct.
when the function is called and output matrix is resulted. the element of the matrix is different.
matrix = inversemat(matrx)
inside function, invmat= 3 1 2, 3 5 1, 8 1 2
outside the function matrix = -9.1249e+61 wtf.
here is the code
int main() {
double matrx[3][3]={{1,2,3},{0,1,4},{5,6,0}};
Mat matrx1(3,3,CV_64F,matrx);
Mat inmat;
inmat=inversemat(matrx1);
[Code] ...
invmat elements are correct, as for inmat the elements are too small -9.212412e+61
What is going on, when the matrix is returned.
View 19 Replies
View Related
Feb 10, 2013
I am new to C++ and I want to learn how to set color a particular color for the users input and output. For example, I want to display the users input as green, and their output as red.
View 2 Replies
View Related
Aug 7, 2013
I'm getting unexpected output in 2 different cases. The 1st deals with bitfields. The C++ standard has this line about integral promotions:
An rvalue for an integral bit-field (9.6) can be converted to an rvalue of type int if int can represent all the values of the
bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field.
If the bit-field is larger yet, no integral promotion applies to it. If the bit-field has an enumerated type, it is treated as any other value of that type for promotion purposes.
This sounds like the value of a bitfield will always be treated as a signed int if the signed representation of the value will fit in the bits. This seems to hold true for my C compiler, but not my C++ compiler.
I tried storing a small negative value in a bitfield that has enough bits to store the sign bit and the value. But when I print out the bitfield, I always get a large number
In the example code below, I expect the output:
Code:
foo.x = -1
foo.y = -2
foo2.x = 31
foo2.y = 6
foo3.x = -1
foo4.x = 4294967295 But I get: Code: foo.x = 31
foo.y = 6
foo2.x = 31
foo2.y = 6
foo3.x = -1
foo4.x = -1 -------------------
The other issue I'm having is sort of similar. I'm trying to store 4294967295 into a float, but when I print it out, I get 4294967296. i've tried storing a few other large values like this and what's printed out is rarely the value I stored. I thought it might be because of some int to float conversion, so I tried 4294967295.0. Still no luck. Then I remember that defaults to a double so maybe that's the issue so I tried 4294967295.0f. Still no luck. Why can't I store the correct value here? I don't think it's an IEE format thing since I can use these values as floats on a calculator program.
The example code showing both issues is below.
Code:
#include <stdio.h>
typedef struct {
signed char x : 5;
signed char y : 3;
}my_struct_t;
[Code] .....
View 11 Replies
View Related
Nov 26, 2013
It's not something trivial but I would like to know the best way to process multiple outputs, for example:
Input
First line of input will contain a number T = number of test cases. Following lines will contain a string each.
Output
For each string, print on a single line, "UNIQUE" - if the characters are all unique, else print "NOT UNIQUE"
Sample Input
3
DELHI
london
#include<iostream>
Sample Output
UNIQUE
NOT UNIQUE
NOT UNIQUE
So how can I accomplish outputs like that? My code so far is:
Code:
int main(int argc, char *argv[]) {
int inputs, count=0;
char str[100];
char *ptr;
scanf("%d",&inputs);
[Code] ....
But the above will obviously print the output after each input, so I want to know how can I achieve the result given in the problem. Also another thing I want to know is, I am using an array of 100 char, which it can hold a string up to 100 characters, but what do I have to do if I want to handle string with no limit? Just declaring char *str is no good, so what to do?
View 5 Replies
View Related
Nov 18, 2013
I have been asked to write a program to grade several multiple-choice exams. The exam has less than 80 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on several files such as exam1.dat where the first line is the key, consisting of a string of n characters (0<n < 80). The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of n characters.
The program should have a while loop in the main routine to ask users input a data file name through keyboard. In this way, the program has a capability of repeatedly asking for a new data file in each while loop until users input a key word “exit”. Once “exit” is encountered, the while loop terminates and your program ends. A typical input exam data file (exam1.dat) looks like:
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
Apply strlen( ) or the length( ) of string to the first line of the above data file for determining the number of questions in the problem. If a student gives more answers than necessary, the extra answers will be automatically truncated. On the other hand, if a student provides less number of answers, the remaining unanswered questions are considered as being answered wrongly.
After users input an exam data file, your program should ask users to input another grade-curving file name (e.g., gradeCurving.dat). This second file contains the information to convert a percentile score to a curved grade in levels of ‘A’ through ‘E’. For instance, a grade-curving file takes the following format: a curved alphabetic grade, a space, a percentile grade served as marker.
A 90
B 80
C 70
D 60
E 50
The above information means that ‘A’ = 90 through 100; ‘B’=80 through 89; ‘C’=70 through 79; ‘D’ = 60 through 69; “E”=50 through 59; For the remaining grades, you can assign an ‘F’.
Furthermore, in each while loop in the main routine, your program should ask users to input an output file name such as score1.dat. The output file will store the scores for each student in a format: student ID number, a space, a percentile score, and a curved grade in ‘A’ though ‘E’. The program should also compute and display the following statistics for the graded answers: Average score, Maximum score, and Minimum score.
A typical output on a data file looks like:
1234567 90% A
9876543 85% B
5554446 95% A
4445556 75% C
5551112 80% B
Statistics:
Average Score: 85%
Minimum Score: 95%
Maximum Score: 75%
This Is what I have so far. It compiles fine and everything but when I input the files it says "There was an error opening the corresponding files. Check input name perhaps?" and it exits out ....
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
int openfiles(ifstream& infile, ifstream& curvingfile, ofstream& outfile);
void Size(ofstream&,int,string);
[Code] ....
View 11 Replies
View Related
Mar 22, 2013
The program works, other than if I place the cursor below the last line in my merch file, the program outputs a line of garbage. The only solution I could find is to leave the cursor on the last line.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct vRecord {
string venue, item;
float price;
[Code]...
View 2 Replies
View Related
Mar 7, 2014
I am trying to build a destructor that takes an array pointer and outputs part of a private vector and, comparing a string within the objects, overwrites the data in the array with the data in the vector. (vector and array use same class type) It then proceeds as usual.
#include <iostream>
#include <string>
#include <iomanip>
[Code].....
View 6 Replies
View Related
Jun 3, 2013
I need to write a program that outputs the number of characters, words, and lines in the files that are supplied as command-line arguments.
#include <iostream>
#include <string>
#include <iomanip>
[Code]....
View 2 Replies
View Related
Apr 15, 2015
I was asked to create a loop that outputs until Quit is entered for customer name. This is what my output is suppose to look like: I will also attach the code I made. Im sure there is something wrong with my while command. But I believe there is something else I have to add to print out the last customer name: quit output.
Lab 28 - Your Name
Input Customer Name: xxxxxxxxxx
Input Customer State: xx
Input Product Price: xxx.xx
Customer Name: xxxxxxxxxxx
Customer State: xx
Product Price: xxx.xx
Product Discount: xxx.xx
Discounted Price: xxx.xx
Sales Tax: xx.xx
Total Cost: xxx.xx
Input Customer Name: Quit
End of Lab 28 for Your Name
Code :
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
double pPrice , pDiscount , dPrice , sTax , tCost ;
int cName , cState ;
[Code] .....
View 4 Replies
View Related
May 2, 2012
A program that outputs all numbers divisible by both 5 and 6.This is what i have written :
#include<stdio.h>
int main () {
int i=200;
int b=10;
while(i<1000)
i b/6%==0
}
where could i have gone wrong.
View 1 Replies
View Related