It does. In my program, the class is defined as follows:
class Node { public: int data; Node* next; Node(); Node (int x, Node* y) { data = x; next = y; } };
What you posted is a declaration of Node::Node() not a definition.
It does. In my program, the class is defined as follows:
class Node { public: int data; Node* next; Node(); Node (int x, Node* y) { data = x; next = y; } };
What you posted is a declaration of Node::Node() not a definition.
Calling this
Node result;
requires node to have a default constructor.
You can't allocate memory to the end of your array. You must allocate the new memory and then copy the existing array into the new memory and then finally delete the old memory.
If the poster will search this section, he'll find a post that shows how to randomly fill an array with unique values...The post was recent(1 - 7 days ago).
A few notes, this is C so main return an integer and you should define your array like below.
#include<stdio.h>
int main()
{
int arr[5][5]={ {2,4,8,11,15},{6,8,5,8,7},{3,5,1,21,72},{28,95,62,8,2},{4,1,7,6,8}};
int i,j,val;
val=arr[0][0];
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
if(val<arr[i][j+1])
{
val=arr[i][j+1];
}
}
printf("\n %d ",val);
return 0;
}
This worked correctly on my machine.
I found this link, it explains how to create a dll with mingw and if you scroll down to the bottom of the page you'll find a link for calling your dll from C#.
Can you do it? Yes, its just a matter of building a string or strings containing the the compiler name and proper switches plus the files in question and then calling system(created_string).
I didn't look over your code because its not enclosed within code tags.
However have you considered that your program does not run continuously since its scheduled ran and rescheduled again.
To quote an earlier posting.
" *plonk* "
But you obviously don't understand what raw machine language really is. That's what I want to create data from and work with and NOT editors of number systems but the REAL machine language its self.
I DON'T want to represent numbers from equivalent values that can be changed I want to do it in PURE MACHINE CODE!
Then find or write an editor that will display binary and go blind in the sea of 0's and 1's.
I'm not. I'm seriously waiting for an answer. It's not wasting peoples' time if they are supposedly here to help.
You do realize that an 'equivalent' value can be represented as a integer, octal, hexadecimal or binary...You realize that right? So you can write raw machine code with a hex editor, I do it all the time.
Save the data to file.
on the one hand i probably complain too much. on the other hand, after a long day at work, i find this coding style with no whitespace, no indentions, no syntax, no nothing, to be unreadable in the most annoying way.
anyhow, sockaddr and sockaddr_in are two different structure types. try this:
if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
.
I"m being picky but this should be
connect(sockfd,(const struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
The errors are pretty self explanatory. Line 3 - you don't have a default constructor for node, line 6 - node doesn't have an operator !=...etc.
I just ran your code and your missing 3, 5, 7.
I think this works...Never checked it with valid prime numbers.
#include<stdio.h>
#define ARR_SIZE 100
int main()
{
int arr[ARR_SIZE], i, j = 1, left;
for(i = 0;i < ARR_SIZE; ++i)
{
arr[i] = j++;
}
for(j = 2; j <= ARR_SIZE; ++j)
{
for(i = j; i < ARR_SIZE; ++i)
{
left = arr[i] % j;
if(left == 0)
{
arr[i] = 0;
}
else
{
continue;
}
}
}
for(i = 0; i < ARR_SIZE; i++)
{
printf("\n %d",arr[i]);
}
return 0;
}
> I don't see why the function has to be so complicated..
Mostly because it reverses characters in the string, not the words. But it is a good start. Once the characters are reversed, you can apply the same function to each individual word, and reach the goal.
This is funny, the OP had a line 'Please tell me how to reverse string in c like taht.' and I assume he meant reverse the string like taht. I didn't realize it was a typo.
here is the code for reversibg string
#include<stdio.h> #include<string.h> char * reverString( char *str) { int strsize, endword, wordReadPos writPos = 0; strsize = strlen(str) -1; char * buffer = (char*) malloc( strsize + 2); while(strsize > 0) { if(str[strsize] == ' ') { buffer[strsize++] = str[strsize--]; } else { endword = strsize; // store the end of word } // now scan for the beging of a word while(strsize >= 0 && str[strsize] != ' ') strsize--; wordReadPos = strsize + 1; while(wordReadPos != endword) { buffer[writPos++] = str[wordReadPos++]; } // copy word } buffer[writePos] = '\0'; strcpy(str, buffer); free(buffer); return 0; }
I don't see why the function has to be so complicated..
void rev_str(char *s)
{
int str_size = strlen(s);
char *end = s + str_size - 1;
while ( s < end )
{
char temp = *s;
*s++ = *end;
*end-- = temp;
}
}
Which assumes the string is writable.
Are you trying to create a double linked list that has a head node and a tail node with zero or more nodes linked in between? Because if that's your intent, you'll have get your 'linked_list_create' to create and link both of them(head and tail node) initially.
The GCC compiler has this option built in, just compile with this option
-ftime-report
example:
g++ filename.cpp -ftime-report -o filename
Hello
I want to reverse the order of my complete string.
I am Learning c
c learning am ILike that.
O.K. could you post what you've attempted.
Line 80
linked_list_push_back(11, 99);
Your passing the number eleven not your linked list pointer ll.
First question. Do you want to display it reversed or do you what to reverse the order in the c string?
I won't handle your condition this way. I would check argc first to see if it indicates a second command line argument. If you find that you have a second command line argument then start parsing the value.
Like so
#include <stdio.h>
int main(int argc, char**argv)
{
if (argc >= 1)/*check for second argument*/
fprintf(stdout, "%s\n", argv[1]);
return 0;
}
You might also want to do something if the guess is too high, too low or correct.
example:
you enter a random number say => 765
The computer guesses 500 which is too low so the next number is one half of the high range => 750...and this continues, taking the top half or bottom half of the remaining range until it hits the number.
Line 24
*chptr='\0';
Is chptr pointing to valid memory?
In C++ you generally create the variables where they are used...In C its considered improper programming style to mixed declarations and code but C++ its O.K.
Firstly, your trying to concatenate onto a string that's immutable
str1="hello";/*creates a immutable c string*/
strcat(str1,s);/*Can't do this for two reasons, one - str1 isn't big enough and two
str1 in immutable*/
I didnt understand, what will be stored in myargv?
could any one tell me what will be the final value of argv?thanks in advance ..
What's stored? A double pointer to char, would it make more sense written like this
char **myargv = &argv[1];
What's the final value? Depends on what the caller of the program sends as command line arguments.
Try the code below
int main(int argc, char *argv[])
{
int port = 1080;
int lsd, sd;
struct sockaddr_in serv_addr, remote_addr;
socklen_t remote_len;
if(argc < 2 || argc > 2) {
printf("Syntax is: %s Directory.\n", argv[0]);
exit (1);
}
if(chdir(argv[1]) == -1){
printf("Cannot change to directory %s.\n",argv[1]);
exit (2);
}
if((lsd = socket(PF_INET, SOCK_STREAM, 0) < 0)){
printf("Cannot create socket.\n");
exit (3);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port);
if (bind(lsd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
printf("Error binding socket to port %d.\n", port);
exit (4);
}
if (listen(lsd, 5) == -1) {
printf("Error listening on socket.\n");
exit (5);
}
remote_len = sizeof(remote_addr);
if ((sd = accept(lsd, (struct sockaddr *) &remote_addr, &remote_len) < 0)) {
printf("Error accepting connection.\n");
exit (6);
}
write(sd, "HELLO WORLD", 12);
close(sd);
close(lsd);
return 0;
}
Line 26
serv_addr.sin_addr.s_addr = INADDR_ANY;
Should be
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
If that fails then try a larger port number like 50000.
You could try googling non-blocking I/O.
Thank You :). How can i print the whole list out in the Main section?
Use a for loop.
To print the first element use code like below.
int i = 0;
fprintf(stdout, "%f\n", num[i]);
Well lets see what you have so far.
The container list has a merge member function, I would look up its functionality.
You need to add an extra for loop like below.
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 5; ++i)
{
for (int j = i + 1; j > 0; --j)
{
cout << i + 1;
}
for (int j = 5 - i - 1; j > 0; --j)
{
cout << 5 - i;
}
cout << 5 - i;
cout << endl;
}
return 0;
}
That's because the system stores the number as 1... 0001 and 1 are equivalent so if you need leading zeros, try storing the value as a string.
We don't have to think...your here.
If the numbers are on the same line..
#include <stdio.h>
#include <stdlib.h>
#define STR_SIZE 10
int main(void)
{
FILE *fp;
char ch[STR_SIZE];
int aInt;
int bInt;
fp = fopen("erogol.k","r");
fscanf(fp, "%s", ch);
aInt = atoi(ch);
fscanf(fp, "%s", ch);
bInt = atoi(ch);
printf("%d \n",bInt+aInt);
return EXIT_SUCCESS;
}
Your going about this the wrong way. Try using fgets() instead of fgetc().
#include <stdio.h>
#include <stdlib.h>
#define STR_SIZE 10
int main(void)
{
FILE *fp;
char ch[STR_SIZE];
int aInt;
int bInt;
fp = fopen("erogol.k","r");
fgets(ch, STR_SIZE, fp);
aInt = atoi(ch);
fgets(ch, STR_SIZE, fp);
bInt = atoi(ch);
printf("%d \n",bInt+aInt);
return EXIT_SUCCESS;
}
The reasons will come with increased usage and eduction.
i am using devc++ code is running..
actually i am not able to install GCC could you let me know how cold i install GCC since info given on their site is not enough
I'll assume your running Windows.
Download Code::Blocks or QT Creator and you'll get a current version of GCC with either or you could try Window's Visual C++ express.
There is no upgrade to that compiler -- it has been dead and buried for quite some time now.
I think using mangled names is common to all linkers -- all Microsoft compilers do that too. It's beyond the scope of a linker to know the unmangled name. The mangled name is actually more useful information because it tells you exactly which of all function overloads caused the problem.
I run a current version of GCC and its linker passes back non-mangled names.
If think you should upgrade your compiler, its passing back mangled names in its error message.
This, on line 81
bool search(int roll,Node **current,Node **previous)
Should be
bool list::search(int roll,Node **current,Node **previous)
nice examples....but i fail to understand your paragraph :/ maybe u can dumb it down for me lol
Templates don't support implicit conversions so they'll create a new functions/objects for each type, hence code bloat.
For small C projects I use Gedit or Vim anything larger and I would switch to C++ and Qt Creator or KDevelop.
Yes, if you take the proper courses..Here's a site you should check out.
Here's a simple function definition and call.
#include <stdio.h>
#include <stdlib.h>
char* getlogin()/*C does not support function overloading*/
{
char *user;
/*do something here*/
return user;
}
int main(int argc, char** argv)
{
char *ans = getlogin();
return (EXIT_SUCCESS);
}
You have five main functions? You should have only one main function.