char p[4]={'h','g','y'};
cout<<strlen(p);
This code prints 3.
char p[3]={'h','g','y'};
cout<<strlen(p);
This prints 8.
char p[]={'h','g','y'};
cout<<strlen(p);
This again prints 8.
Please help me as I can't figure out why three different values are printed by changing the size of the array.
Hi. I am building a 16 bit operating system. But character array does not seem to work.
Here is my example kernel code:
asm(".code16gcc\n");
void putchar(char);
int main()
{
char *str = "hello";
putchar('A');
if(str[0]== 'h')
putchar('h');
return 0;
}
void putchar(char val)
{
asm("movb %0, %%al\n"
"movb $0x0E, %%ah\n"
"int $0x10\n"
:
:"m"(val)
) ;
}
It prints:
A
that means putchar function is working properly but
if(str[0]== 'h')
putchar('h');
is not working.
I am compiling it by:
gcc -fno-toplevel-reorder -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0
What should I do?
Suppose I have a Dictionary<String,String>, and I want to produce a string representation of it. The "stone tools" way of doing it would be:
private static string DictionaryToString(Dictionary<String,String> hash)
{
var list = new List<String> ();
foreach (var kvp in hash)
{
list.Add(kvp.Key + ":" + kvp.Value);
}
var result = String.Join(", ", list.ToArray());
return result;
}
Is there an efficient way to do this in C# using existing extension methods?
I know about the ConvertAll() and ForEach() methods on List, that can be used to eliminate foreach loops. Is there a similar method I can use on Dictionary to iterate through the items and accomplish what I want?
I am trying to parse a string timestamp of format "yyyyMMddHHmmss" with DateTime.ParseExact(). The catch is I must allow for an hour value of "24" (i.e. hours can be from 0 to 24; Note: I can't control the input values.) and, of course, that results in an exception.
Are there any settings/properties I can set instead of manually parsing/using regex's? If not, any efficient parsing ideas?
ex.
DateTime.ParseExact("20120911240000", "yyyyMMddHHmmss",
System.Globalization.CultureInfo.InvariantCulture);
hour 24 means hour 0 of next day (so day + 1, hour = 0)
Hi all,
I have a set of data that contains garbled text fields because of encoding errors during many import/exports from one database to another. Most of the errors were caused by converting UTF-8 to ISO-8859-1. Strangely enough, the errors are not consistent: the word 'München' appears as 'München' in some place and as 'MÜnchen'.
Is there a trick in SQL server to correct this kind of crap? The first thing that I can think of is to exploit the COLLATE clause, so that ü is interpreted as ü, but I don't exactly know how. If it isn't possible to make it in the DB level, do you know any tool that helps for a bulk correction? (no manual find/replace tool, but a tool that guesses the garbled text somehow and correct them)
/^[^\s]+\s([^\s]+)\s/
In PHP,I can use regex to get the substr by $1,
how should I do it in C?
It's better if can do it without regex,though.
UPDATE
Put simply, how do I get werwerur out of swerwer werwerur y (the second)?
Problem: Visual C++ 10 project (using MFC and Boost libraries). In one of my methods I'm reading simple test.txt file.
Here is what inside of the file (std::string):
12 asdf789, 54,19 1000 nsfewer:22!13
Then I'm reading it and I have to convert all digits to int only with boost methods. For example, I have a list of different characters which I have to parse:
( ’ ' )
( [ ], ( ), { }, ? ? )
( : )
( , )
( ! )
( . )
( - )
( ? )
( ‘ ’, “ ”, « » )
( ; )
( / )
And after conversation I must have some kind of a massive of int's values, like this one:
12,789,54,19,1000,22,13
Maybe some one already did this job?
PS. I'm new for boost.
Thanks!
How can I serialize a python Dictionary to JSON and pass back to javascript, which contains a string key, while the value is a List (i.e. [])
if request.is_ajax() and request.method == 'GET':
groupSet = GroupSet.objects.get(id=int(request.GET["groupSetId"]))
groups = groupSet.groups.all()
group_items = [] #list
groups_and_items = {} #dictionary
for group in groups:
group_items.extend([group_item for group_item in group.group_items.all()])
#use group as Key name and group_items (LIST) as the value
groups_and_items[group] = group_items
data = serializers.serialize("json", groups_and_items)
return HttpResponse(data, mimetype="application/json")
the result:
[{"pk": 5, "model": "myApp.group", "fields": {"name": "\u6fb4\u9584", "group_items": [13]}}]
while the group_items should have many group_item and each group_item should have "name", rather than only the Id, in this case the Id is 13.
I need to serialize the group name, as well as the group_item's Id and name as JSON and pass back to javascript.
I am new to Python and Django, please advice me if you have a better way to do this, appreciate. Thank you so much. :)
Hi
I am trying to dump the floating point values from my program to a bin file. Since I can't use any stdlib function, I am thinking of writting it char by char to a big char array which I am dumping in my test application to a file.
It's like
float a=3132.000001;
I will be dumping this to a char array in 4 bytes.
Code example would be:-
if((a < 1.0) && (a > 1.0) || (a > -1.0 && a < 0.0))
a = a*1000000 // 6 bit fraction part.
Can you please help me writting this in a better way.
I have code like that:
TEXT_TO_FILTER='I would like to replace this $var to proper value'
var=variable
All I want to get is:
TEXT_AFTER_FILTERED="I'd like to replace this variable to proper value"
So I did:
TEXT_AFTER_FILTERED=`eval echo $TEXT_TO_FILTER`
TEXT_AFTER_FILTERED=`eval echo $(eval echo $TEXT_TO_FILTER)`
Or even more weirder things, but without any effects.
I remember that someday I had similar problem and I did something like that:
cat << EOF > tmp.sh
echo $TEXT_TO_FILTER
EOF
chmod +x tmp.sh
TEXT_AFTER_FILTERED=`. tmp.sh`
But this solution seems to be to much complex.
Have any of You heard about easier solution?
Working in ASP.NET (VB), I am trying to develop a simple search results page for my website.
The process is as follows:
(1) The site's user enters a search phrase;
(2) The search results page searched the site's database, and returns the page title as a link, and a short snippet from each search "hit", with the search phrase highlighted.
I already have the search part done, and also the "highlighted" part done (using Regex). However, I want to be able to return a short snippet of text, which include the search phrase (a few words before the search phrase, a few after). Something like:
Page Title [as a link]
... yada yada yada search phrase yada yada yada...
Hello,
I have a complicated form where I first have to take some _GET parameters and obviously I have to do a mysql_real_escape_string() on them since I look stuff up in the database with them.
Them problem for me is after the initial db lookup. When the user submits a form, I send them along as a _POST request and obviously have to do this mysql_real_escape_string call again just in case someone tries to hack my site with a faked form submission.
Then the problem I have is the arguments are escaped twice and my queries begin to look strange like this:
select field1 , field2 , from my_table where some_id = \'.$lookup_id.\' ...
So the system seems to be adding \' and it is messing me up :)
Also, in my other forms I have not seen such behavior. Any ideas on what may be causing this?
One weird thing is that I tried to send unescaped parameters to the post, and the same problem happens. That is a clue, but not a sufficient one for me. :(
Thanks,
Alex
Well since it seems relatively difficult to send the object of a WebControl over JSON using jquery.ajax() I've decided to send the name of the control as a string because I know how to do that. Then I promptly realized that, from a web service, I don't actually know how to search for a control by ID name. Since its a service I can't seem to get Control.FindControl() to work so does anyone have ideas or suggestions? All I'm trying to do is call a databind() on my radcombobox.
Thanks in advance!
For any of you that knows anything about asp.net/rad controls - I'm basically updating a database and want the radcombobox to be in sync with that database again after adding something, before I autoselect what was just added. Other than databind do i have to call anything to refresh that list?
Thanks again!
This script should detect the last portion in the full path, and if it is stackoverflow output ok
$current_url = $_SERVER['REQUEST_URI'];
$current_url_arr = explode('/',$current_url);
$count = count($current_url_arr);
if($current_url_arr[$count-2] == 'stackoverflow'){
echo 'ok';
}
else {
echo 'not ok';
}
Example 1: www.myserver.ext/something/else/stackoverflow/
Output: ok
Example 2: www.myserver.ext/something/else/stackoverflow
Output: not ok
Example 3: www.myserver.ext/something/else/stackoverflow/foo
Output: not ok
I hope that you understand the idea. This script works fine, but I'm wondering if there is any better, elegant way to read last portion of URL?
function FM_log(level, text) {
// caso não seja log total escolhe o que loga
var log = false;
switch (level) {
case "addtoprio()":log = true;
case "alternaTropas()":log = false;
case "sendtroops()":log = false;
defalt: log = false;
}
if ((logTotal == false) && (log == true))
GM_log(horaAtual() + " - "+level+", "+text);
else if (logTotal == true)
GM_log(horaAtual() + " - "+level+", "+text);
}
how to do that switch is a way it works?
The challenge: The shortest code, by character count, that detects and removes duplicate characters in a String. Removal includes ALL instances of the duplicated character (so if you find 3 n's, all three have to go), and original character order needs to be preserved.
Example Input 1:
nbHHkRvrXbvkn
Example Output 1:
RrX
Example Input 2:
nbHHkRbvnrXbvkn
Example Output 2:
RrX
(the second example removes letters that occur three times; some solutions have failed to account for this)
(This is based on my other question where I needed the fastest way to do this in C#, but I think it makes good Code Golf across languages.)
I have got a file with following format.
1234, 'US', 'IN',......
324, 'US', 'IN',......
...
...
53434, 'UK', 'XX', ....
...
...
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Here I want to extract only those lines having 'IN' as 2nd keyword. i.e.
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Can any one please tell me a command to grep it.
Hi all,
This is probably seriously easy to solve for most of you but I cannot solve this simply putting str() around it can I?
I would like to convert this list: ['A','B','C'] into 'A B C'.
Thanks in advance!!
Hello, I'm writing an IRCd. For this topic it doesn't really matter if you know much about IRC. Its a simple code style problem.
Quick overview of the problem:
No message may be longer than 512 characters
If the message is more, it must be broken into pieces
The NAMES reply sends all the nicknames of users on a channel, and quickly grows beyond 512 characters.
I currently concocted this marvelous piece of code, it works perfectly. However, its just not "ruby-like". This piece of code is more what you expect in some piece of C code.
# 11 is the number of all fixed characters combined in the reply
pre_length = 11 + servername.length + mynick.length + channel.name.length
list = [""]
i = 0
channel.nicks.each do |nick, client|
list[i+=1] = "" if list[i].length + nick.length + pre_length > 500
list[i] << "#{channel.mode_char(client)}#{client.nick} "
end
list.each { |l| send_numeric(RPL_NAMREPLY, channel.name, l.strip) }
send_numeric(RPL_ENDOFNAMES, channel.name)
So my question is, any ideas to do this more nicely?
PS. code has been slightly modified to make it easier to understand out-of-context
I have SEF urls like /sitename/section/12-news-title and number 12 is id of the news. I need to get that number 12 in my php code, is there any out of the box method in PHP for this?
Hello,
I have a database on a SQL Server 2000 server. This database has a table called "Person" that has a field call "FullName" that is a VARCHAR(100).
I am trying to write a query that will allow me to get all records that have a name. Records that do not have a name have a FullName value of either null or an empty string. How do I get all of the Person records have a FullName? In other words, I want to ignore the records that do not have a FullName. Currently I am trying the following:
SELECT
*
FROM
Person p
WHERE
p.FullName IS NOT NULL AND
LEN(p.FullName) > 0
Thank you
Hi,
do you know any good algorithms that match two strings and then return a percentage in how many percent those two strings match?
And are there some, that work with databases too?
I've seen questions to prefix zeros here in SO. But not the other way !!
Can you guys suggest me how to remove the leading zeros in alphanumeric text. Are there any built-in APIs or do I need to write a method to trim the leading zero's?
Example:
01234 converts to 1234
0001234a converts to 1234a
001234-a converts to 1234-a
101234 remains as 101234
2509398 remains as 2509398
123z remains as 123z
000002829839 converts to 2829839