In C++
day = 'p'
is the assignment operator not the comparison operator...You want
day == 'p'
See line 57
In C++
day = 'p'
is the assignment operator not the comparison operator...You want
day == 'p'
See line 57
Here's a solution but it assumes a few things
1. Your passing a c-string...I use strlen() which requires a c-string
2. The c-string passed has room for the extra character.
#include <stdio.h>
#include <string.h>
char* append_it(char *cptr, const char c)
{
int len = strlen(cptr);
cptr[len + 1] = cptr[len];
cptr[len] = c;
return cptr;
}
int main()
{
char test[10] = {'A','B','C','\0'};
fprintf(stdout, "new c-string->%s\n", append_it(test, 'D'));
fprintf(stdout, "new c-string->%s\n", append_it(test, 'E'));
return 0;
}
Firstly
char* test = "ABC"
creates a read only c-string so you can't modify it...
You want something like
char test[10] = {'A','B','C','\0'};
Try running this code
#include <stdio.h>
int one, two;
int main()
{
printf("Enter two numbers->\n");
scanf("%d - %d", &one, &two);
fprintf(stdout, "one->%d, two->%d\n", one, two);
return 0;
}
First enter your numbers like this
34 56
and then try entering your numbers like
34 - 56
Try this link
See if you can find what I changed...
#include <stdio.h>
int NumericalAnswer;
int score = 0;
int main()
{
printf("Question 1: What's 4 x 3?\n");
scanf("%d", &NumericalAnswer);
if (NumericalAnswer == 12)
{
printf("You got it right!");
score += 1;
}
return 0;
}
By size? Do you mean height or weight?
Because its syntactically illegal. Check this link...
http://www.neu.edu.cn/cxsj/materal/otherc/imada/subsection3_6_2.html
"I heard in class that dynamic arrays like in java aren't supported"
Hmmmm, yes they are. Try a vector.
I know this is probably radical but why don't you write some code, like below, and try it yourself.
#include <stdio.h>
#include <stdlib.h>
struct mystr
{
unsigned int a;
unsigned int b;
unsigned int c;
}thestr[3] = {{0,},};
int main(int argc, char**argv)
{
int i;
for (i = 0; i < 3; ++i)
{
fprintf(stdout, "a->%u\n", thestr[i].a);
fprintf(stdout, "b->%u\n", thestr[i].b);
fprintf(stdout, "c->%u\n", thestr[i].c);
}
exit(EXIT_SUCCESS);
}
I'm not familiar with mac but I would ensure that you have a proper file path and the permissions to create a file.
A few things...First what doesn't work? Next you should check to see if fopen was successful.
dblPoint = fopen(BINDATA, "wb");
Did fopen succeed or fail here?
Ok, so I'm leaving my struct-based date idea. I'll pass the data directly in a sequence of write().
Thank you for the reply.
You should really check the XDR library, it'll make passing data through a network a snap.
The easiest way is the functionality in the XDR library(eXternal Data Represention) or if your not familiar then you could pass non c-string data by passing the start address and the length...Like this.
unsigned int mydata = 1234;
write(clientfd, &mydata, sizeof(mydata));
Please note, you cannot pass pointers and expect the receiver to use them without failure....You must pass the data that the pointer points to..
The biggest thing that I see is line 30 you call calcData() but downpayment, mort_gage, loan are uninitialized..
I only quickly looked at your code...I couldn't find a != operator for decimal.
I see one potential problem here. You have a forward declaration class Retriever..Which makes me wonder??? If you have a Alsation object and call your friend function which has a reference to a Retriever how do you intend to handle the fact that your data members may deficient for a Retriever?
It seems to me that this function would make more sense as a non-friend/non-member function defined after both Retriever and Alsation.
Because its aligned 2 bytes its guaranteed that the address & 0x1 will return 0...Check out the attached code..
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char**argv)
{
int i = 0;
char __attribute__((aligned(2))) ch1;
char *cptr = &ch1;
for (i = 0; i < 20; ++i)
{
fprintf(stdout, "ans->%u\n", ((unsigned int)(unsigned long)cptr & 0x1));
cptr += 2;
}
exit(EXIT_SUCCESS);
}
The output is ans->0 for all iterations...Why do they have a function that tests for this? I really don't know.
Actually I made the reply before coffee...These remarks indicate
/*
085 * Note that all tvec_bases are 2 byte aligned and lower bit of
086 * base in timer_list is guaranteed to be zero. Use the LSB for
087 * the new flag to indicate whether the timer is deferrable
088 */
That your masking out the bit of struct tvec_base *base with 0x1 and returning the value.
To see what's just do some substitution...
#define TBASE_DEFERRABLE_FLAG (0x1)
struct tvec_base *base
First we cast base to unsigned long
(unsigned long)base
Then we perform the bit operation & on
(unsigned long)base & 0x1
Then we cast our result to
(unsigned long)(unsigned long)base & 0x1
Why do it this way? It may be a simple trick to manipulate the spinlock_t variable in
struct tvec_base {
spinlock_t lock;
struct timer_list *running_timer;
unsigned long timer_jiffies;
struct tvec_root tv1;
struct tvec tv2;
struct tvec tv3;
struct tvec tv4;
struct tvec tv5;
} ____cacheline_aligned;
Note I said 'may' be a way.
I don't know why your allocating memory because s1 is supposed have enough room to append s2 onto it..
Here's a simple example that came with my help files
char*
strncat(char *dest, const char *src, size_t n)
{
size_t dest_len = strlen(dest);
size_t i;
for (i = 0 ; i < n && src[i] != '\0' ; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}
And also, it wont let me use getline(cin, input, '@@@'), if I try to enforce that condition.
Thanks in advance.
That's because the delimiter has to be a character....'@' is a character but '@@@' is not.
Why did you post your C++ question in the C section?
This function strcpy() expects c-strings not characters
strcpy(array1[n],array);
array1[n] and array are characters.
I think if you look closely, you'll find that your switch statement is outside your loop.
This is your for loop
for (i = 0; i < 32; ++i)
grade[i] = 0;
To include the switch you'll need to add braces like
for (i = 0; i < 32; ++i)
{
grade[i] = 0;
switch(something)
{...}
}
If this points to a structure..
process *state_of_queue = fcfs(q);
Then use
state_of_queue->structure_member
or
(*state_of_queue).structure_member
Thanks myk45 for your help.
Now, about the second question.. I don't want to allocate less of bytes, but lets say I did that.. why it won't return a segmentation fault?
I just want to understand what is going on if I allocate less bytes..
It probably depends on you memory manager and how it doles out memory.
If this is a custom environment then you'll probably have to create a special linking/compiling process so your exe will execute.
In truth I'm not really sure what your after? The boot floppy, is it one you created or is it one you downloaded? The kernel I have the same questions, is it one you created or is it one you downloaded?
Ooops I double posted by accident...Can a moderator remove this one..Thanks.
I'm guessing its the p[p] part. Well its simple if you break it down..
We'll look at the inner p which just returns the i-th element of the array. The value from the inner p is used as the 'index value' of the outer p[index value]. Its a little unorthodox to use an array this way.
What line(s) are you having problems with?
If you insist on doing it this way then try the string's [] operator.
int i = fullName.length();
cout<<"Your reversed full Name is: ";
while (i>=0)
{
cout<<fullName[i];
i--;
}
Please note that the string object has iterators which would handle this problem nicely.
Please get out of the habit of using gets(), its a very dangerous function. A much better solution is fgets().
Also...
Your while statement assumes that the fetched c-string is 80 characters long?
while(i!=80)
shouldn't it be
while(i <= strlen(array))
Also this next line is incorrect
if(array[i]==(('a')||('A')||('e')))
It should be
if ( array[i] == (('a') || array[i] == ('A') || array[i] == ('e')))
Plus we have move vowels than 'a' and 'e'
Because that's the size of the pointer and not the size of the c-string. Try displaying the pointer with
std::cout << (void*)p << std::endl;
Could it be the new line character in the fgets() fetched c-string.
'It gives me a "bad_alloc" error when the obj is instantiated.'...Which object?
I tried compiling your code but you have MS specific functionality....scanf_s doesn't work with Linux...
Could you post an example of the file or post the shell script?
If you know how to test for one blank...then test for another one?
Which operating system?
I know how to solve this in Linux using GCC but the solution is not portable...That said you should be able to use the concept which is....wrapping the C++ functionality in a C calling sequence, see below
testit.cpp
#include <iostream>
extern "C" void PrintStr(char *str);
void PrintStr(char *str)
{
std::cout << "From Cpp Object file->" << str << std::endl;
}
testit.h
void PrintStr(char *str);
test.c
#include "testit.h"
int main()
{
char ch[] = "From the C program";
PrintStr(ch);
return 0;
}
And my compile lines
g++ -Wall -ansi -pedantic -c testit.cpp
gcc testit.o test.c -o test -Wall -ansi -pedantic -lstdc++
Note the inclusion of the standard C++ library with the -lstdc++ switch..Hope this helps.
Output:
From Cpp Object file->From the C program
The question is...What were you expecting? Was it something like below
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char* argv[])
{
unsigned char p[] = {'1', '1', '1', '1'};
unsigned char a[4];
for(int i = 0; i < 4; i++)
{
a[i] = ~(p[i] - '0');
}
for(int i = 0; i < 4; i++)
{
cout << (unsigned int)a[i] << endl;
}
}
Which produces
254
254
254
254
Well once for erek and once for the copy of erek in the function call.
yeah i know this tutorial and i try it out but it did not work
I wrote something like this but didn't use C++, I used asm(16 bit) plus had to write my own linker script to get it to work...
Projects like this are very interesting and the end result is generally a very simple exe that will boot the computer...I would try ams if your really interested in pursuing this.
Here's another link..
Do you mean, how does a C object file that has been linked into a C++ project, retrieve/accept the GUID of an object?
I'm not certain which binutils(binary utilities) are valid/available with that version but I would Google around and find out...
You could try
nm filename
Which should display all the symbols from the object file
Here's a link for a list of the GNU GCC compilers binutils
Ooops I assumed your were running a Linux based system with Executable Linkable Format(elf)..Are you compiling this on Windows or Linux/Unix and what binutils are available?
Try creating a small exe with the gcc compiler then use the binutil
readelf -a exename
It should display all the information you need..
Two c-strings are identical if, the starting addresses are the same or if different(starting addresses) the characters that constitute the c-string are the same.
First question. What is t[] an array of, characters? I ask because you pass 1 as the size in your write function.
Second question...You have
int val;
read(fd[0],&val,1);
val is an integer...its size should be sizeof(int)...e.g.
read(fd[0], &val, sizeof(int));
Third question...Well more of a pointer
write(fd[1],t,1);
should be
write(fd[1],&t,sizeof(whatever t is));
I'm a little confuse...Do you want a program that will take an inputted binary number and then produce its decimal equivalent?
e.g.
enter a binary number->111
ans->7
Is that what you want?