gerard4143 371 Nearly a Posting Maven

Should you be using \ here

"C:\Users\bt\Desktop\perl_files";

Shouldn't it be

"C:/Users/bt/Desktop/perl_files";

I think you can the rest here

http://perldoc.perl.org/functions/-X.html

gerard4143 371 Nearly a Posting Maven

This link will show you how to get file size

http://perlmeme.org/faqs/file_io/filesize.html

You'll have to elaborate on date. Do you mean creation data or last accessed date or last modified date?

gerard4143 371 Nearly a Posting Maven

Try this

my @files = sort { $a cmp $b } readdir(DIR);

I tried this and it worked.

#!/usr/bin/perl

use strict;
use warnings;

my $dir = 'directory_path';

opendir(DIR, $dir) or die $!;

foreach( sort { $a cmp $b } readdir(DIR))
{
        next if (/^\./);
        print $_,"\n";
}

closedir(DIR);
exit 0;
gerard4143 371 Nearly a Posting Maven

Right click on the file in question and select properties. The properties window should have a field 'Full File Path'. If your looking to list the files for the entire project then try the main menu option Edit->Find and choose the proper file name patterns.

gerard4143 371 Nearly a Posting Maven

Try looking up a function like popen.

gerard4143 371 Nearly a Posting Maven

It might help if you include the version of Netbeans, C/C++ plugin and your compiler.

gerard4143 371 Nearly a Posting Maven

Well you could parse the c-string with strtok.

gerard4143 371 Nearly a Posting Maven

You need to modify this line to
scanf("%d", &arr[i]);
Note the &.

gerard4143 371 Nearly a Posting Maven
player->draw(s); //errors are these 3 lines, s is an undeclared identifier

So where is s defined?

gerard4143 371 Nearly a Posting Maven

@ Ancient D.
Yes I agree with your point but I'm interested in sorting a standard container called say 'first_container' via another container which has iterators pointing to the first container. Hope that makes sense.

gerard4143 371 Nearly a Posting Maven

Which line is the function called on?

gerard4143 371 Nearly a Posting Maven

Again 'Need Help ASAP' is not a good title.

gerard4143 371 Nearly a Posting Maven

Could you narrow down your problem to something smaller than the entire program?

P.S. Please use an appropriate title for your posting. Need Help ASAP isn't very descriptive.

gerard4143 371 Nearly a Posting Maven

Does anyone know how to do this?

I attached a program that collects all the command line arguments into a map container noting how many times each command line argument occurs. Now I want to sort this map of information by loading a vector with iterators that point to each map element and sort the iterators. I'm just wondering, what is the best way to do this. My method works but I'm wondering is it the proper way to do it?.

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>

struct mys
{
    unsigned long a;
};

std::ostream& operator <<(std::ostream & out, const struct mys & m)
{
    return out << m.a;
}

std::ostream& operator <<(std::ostream & out, const std::pair<const std::string, struct mys> & p)
{
    return out << p.first << " " << p.second;
}

std::ostream& operator <<(std::ostream & out, const std::map<std::string, struct mys>::const_iterator & i)
{
    return out << *i;
}

bool compare_iterator(const std::map<std::string, struct mys>::const_iterator & a, const std::map<std::string, struct mys>::const_iterator & b)
{
    return a->second.a > b->second.a || ( a->second.a == b->second.a && a->first > b->first );
}

int main(int argc, char** argv)
{
    std::map<std::string, struct mys> the_words;
    std::vector<std::map<std::string, struct mys>::const_iterator > the_vec;

    for (std::map<std::string, unsigned long>::size_type i = 1; i < argc; ++i)
        the_words[argv[i]].a++;

    std::map<std::string, struct mys>::const_iterator begin = the_words.begin();
    std::map<std::string, struct mys>::const_iterator end = the_words.end();

    while ( begin != end )
    {
        the_vec.push_back(begin);
        ++begin;
    }

    sort(the_vec.begin(), the_vec.end(), compare_iterator);

    copy(the_vec.begin(), the_vec.end(), std::ostream_iterator<std::map<std::string, struct mys>::const_iterator >(std::cout, "\n"));

    return 0;
}
gerard4143 371 Nearly a Posting Maven

The return value of fork() will explain your questions

RETURN VALUE
On success, the PID of the child process is returned in the parent, and 0
is returned in the child. On failure, -1 is returned in the parent, no
child process is created, and errno is set appropriately.

gerard4143 371 Nearly a Posting Maven

Because Perl has so many esoteric built-in variables like - @_ or $_ or $. or $` or $& or $' or $^I...it can make the code very messy(like line noise) to the uninitiated .

gerard4143 371 Nearly a Posting Maven

Try something like below:

#include <stdio.h>

int main()
{
  size_t i = 0;
  union a
  {
    int i;
    char ch[sizeof(int)];
  };

  union a u;

  for (i = 0; i < sizeof(int); ++i)
  {
    if (i == 0) 
      u.ch[i] = 1;
    else
      u.ch[i] = 0;
  }

  printf("%d %d %d\n",u.ch[0],u.ch[1],u.i);

  return 0;
}
gerard4143 371 Nearly a Posting Maven

How are your integers stored? Big or small endian? Also, are your integers 2 or 4 bytes?

gerard4143 371 Nearly a Posting Maven

Number one. If your passing a pointer to an array then your function should accept a pointer to an array.

int listrented(cars_t * cars2)
{
  printf("Testing...\n");
  /*shoud return something here*/
}

Number two. When you call a function, you don't declare the varibles

> if(choice == 3) listrented(cars_t cars[]);

/*should be*/

> if(choice == 3) listrented(cars);
gerard4143 371 Nearly a Posting Maven

It doesn't matter, its just uninitialized memory. Why do you think its a memory pointer? It could just as easily be a signed/unsigned interger...Memory is not self defining, its whatever we(the program) say it is.

gerard4143 371 Nearly a Posting Maven

Odd I thought someone would have some comments on this code. I guess the second attempt 'the hack' is acceptable code.

gerard4143 371 Nearly a Posting Maven

A pointer is just a variable, so coping a pointer into a pointer is done just like you showed.

    char *name1; 
    char *name2; 

    name2 = name1;

Now both name2 and name1 point to the same memory area.

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

On line 27 you have a semi-colon

else if (s[n] == 12); { 

I think that's your problem

gerard4143 371 Nearly a Posting Maven

I think you should use a for statement to loop through your myArr array, comparing each element to the calculated average.

gerard4143 371 Nearly a Posting Maven

Maybe, in advance, you could give us a brief description of what the code is supposed to do.

gerard4143 371 Nearly a Posting Maven

I have a question about istream iterators and reading the input to the EOL. How do you do it? I tried the following but had to revert to a hack to get it to work.

My first attempt reads from the istream but a word at a time.

first.cpp

#include <iostream>
#include <string>
#include <vector>
#include <iterator>

int main(int argc, char** argv)
{
    std::vector<std::string> the_words;

    std::istream_iterator<std::string> in(std::cin);
    std::istream_iterator<std::string> CIN_EOF;

    while ( in != CIN_EOF )
    {
        the_words.push_back(*in);
        ++in;
    }

    std::vector<std::string>::const_iterator begin = the_words.begin();
    std::vector<std::string>::const_iterator end = the_words.end();
    std::vector<std::string>::size_type count = 0;

    while ( begin != end )
    {
        std::cout << "[" << ++count << "] - " << *begin << std::endl;
        ++begin;
    }

    return 0;
}

The output for the above code is:

this is the first
this is the second
this is the third
[1] - this
[2] - is
[3] - the
[4] - first
[5] - this
[6] - is
[7] - the
[8] - second
[9] - this
[10] - is
[11] - the
[12] - third

Note the code is reading a word then pushing it onto the vector the_words.

My second attempt works but I feel its a bit of a hack. Does anyone know a better way?

hack.cpp

#include <iostream>
#include <string>
#include <vector>
#include <iterator>

class myc
{

public:

    operator std::string() const { return str; }

    std::string str;

};

std::istream& operator >>(std::istream & in, myc & m) …
gerard4143 371 Nearly a Posting Maven

Please delete this...I'm new to the new Daniweb format.

gerard4143 371 Nearly a Posting Maven

Try these compiler settings.

gcc -O0 -fno-stack-protector -z execstack -o testit testit.c
gerard4143 371 Nearly a Posting Maven

@gerard4143 : All I am trying to do is mprotect the whole stack right from 0xffffffff till the current stack pointer.

So I was hoping,

1. Get the current stack pointer
2. Get the Page-aligned address for that stack pointer (which will not run into another page)
3. mprotect it from here till the beginning (0xffffffff)

I dont see how posix_memalign() could be of any help here. Could you please explain ? Thanks.

You have a few problems with your task or easier ways to accomplish your goals.

1. You can't access the upper range of addresses in a user process. Its reserved for the kernel and kernel mode.
2. You can change the attributes of the stack with the compiler....This is probably the easier way to accomplish your goal.
3. Your stack may indeed be larger than a page.

gerard4143 371 Nearly a Posting Maven

@gerard4143 : Thanks for the reply. I have doubt. In the code

unsigned long addr = (unsigned long)&main & ((0UL - 1UL) ^ (MY_PAGE_SIZE - 1));

if main is address of one of the local variable, say 0xabcd8000, then the formula provided gives the address of the aligned-page( say 0xabcd6000 which is lesser than the address of the local variable). My question is, is this answer the address of the next page or the address of the current page ? I got this confusion because given that stack is growing down and the resultant address is lesser than the local variable address, I was rather expecting the resultant to be greater than the address of the local variable.

Hence If I am to copy the page containing the local variable (4K-pagesize), should I use the resultant or the (resultant-4096)address ? Am I making myself clear ?

If possible, could you explain how this piece of code works ?

It returns the page where main resides...Actually it returns the page where main starts, I say this because main could span one or many pages.

I would forget the above code and concentrate on the posix_memalign() function.

gerard4143 371 Nearly a Posting Maven

Actually I forgot...POSIX has a function called posix_memalign(), which will allocate your memory aligned on a memory border.

gerard4143 371 Nearly a Posting Maven

Well the first thing you'll have to do is determine page size on your computer. Then you could try something like below.

#include <stdio.h>
#include <stdlib.h>

#define MY_PAGE_SIZE 4096

int main(int argc, char** argv)
{
    unsigned long addr = (unsigned long)&main & ((0UL - 1UL) ^ (MY_PAGE_SIZE - 1));
    void * ptr = (void*)addr;/*ptr aligned on page*/
    
    return (EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Wow I won't be forking a process that's already sporting an extra thread(the event loop).

gerard4143 371 Nearly a Posting Maven

Well 9 divides into 1 zero times with 1 left over.

gerard4143 371 Nearly a Posting Maven

Just use

struct mys
{};

struct mys * pointer = (struct mys*)malloc(num_elements * sizeof(struct mys));
gerard4143 371 Nearly a Posting Maven

Thanks For your replay
but i do not know any thing in c
can you write the code please.

No, absolutely not.

gerard4143 371 Nearly a Posting Maven

Because goto can have devastating results on your program and program flow its frowned on. If you really need to jump all over your program try a safe function like longjmp().

void longjmp (jmp_buf env, int val);
int setjmp ( jmp_buf env );
gerard4143 371 Nearly a Posting Maven

It really depends on your extraction criteria but I would start investigating functions like strtok().

gerard4143 371 Nearly a Posting Maven

Have you tried using a library like


http://gmplib.org/

gerard4143 371 Nearly a Posting Maven

Isn't Cygwin a Windows compiler and termios.h a Linux/Unix header?

gerard4143 371 Nearly a Posting Maven

The error message tells it all. The case needs to be a constant...Like

1,2,3,4,5...or

#define one 1
const unsigned long two 2;

switch(angle)
{
case:1
{}
case:two
{}
}
dij_0983 commented: right :) +2
gerard4143 371 Nearly a Posting Maven

Your kidding right? Demanding free help.

gerard4143 371 Nearly a Posting Maven

I think you should consider a few problems with your approach.

1. What if your pointer, points to dynamic memory that's been freed.
2. What if your pointer, points to memory on the stack that's been released.

gerard4143 371 Nearly a Posting Maven

Really and we're just supposed to know what this does.

gerard4143 371 Nearly a Posting Maven

Sure we'll help. What's your question or problem? Well besides its not working.

gerard4143 371 Nearly a Posting Maven

Wow what compiler are you using - #include <iostream.h>

gerard4143 371 Nearly a Posting Maven

borland c++ is fastest

Why do people keep reviving these old threads?

gerard4143 371 Nearly a Posting Maven

You could use the static keyword but I would create the array on the heap.

int* Bar(){

int * array = new int[2];
array[0] = 1;
array[1] = 2;

return array;

}

Just remember that you have to track and maybe delete [] this array.

gerard4143 371 Nearly a Posting Maven

Integer size is generally 4 bytes however char is only 1 byte your error is caused by thisissue in my opinion

You realize this thread is 8 years old.