/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

45.32.80.36/board.cgi
en.wikipedia.org/wiki/IEEE_floating_point
en.wikipedia.org/wiki/Single-precision_floating-point_format
ridiculousfish.com/blog/posts/old-age-and-treachery.html
twitter.com/SFWRedditGifs

First for D

>Degenerate shit
Kill yourself

Still working on my C comment board!
45.32.80.36/board.cgi

I added a post cooldown timer!
>todo: add page browsing, image attachments

unsigned int max = ~0;

>0, of course, is all 0s: 00000000 00000000. Once we twiddle 0, we get all 1s: 11111111 11111111. Since max is an unsigned int, we don't have to worry about sign bits or twos complement. We know that all 1s is the largest possible number.

But what about unsigned? How do I get floats max?
float a = ~0;
printf("%g\n", a);

This gives me -1, which I'm assuming is because of the above stated about signed/unsigned types.

std::numeric_limits::max

Asking for help again. If i can figure out these fucking code tags. I need to have 0 print out "zero". But it keeps fucking up my do while loop. Adding it to the array don't work either.

#include

int countDigits(int value);
void convert(int number);

char *ones[]={"", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine","ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"};

char *tens[10]={"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"};


int main(void)
{
int inputNum;
printf("Enter numbers in figures; use a negative value to stop..\n");
// continue running loop until a negative # is entered
do{
printf("\nNumber: ");
scanf("%d", &inputNum);
//special case for zero
/*if(inputNum==0){
printf("zero");
} */
//check if user entered over 999999.
if(inputNum>999999)
{
printf("Only numbers less than 999999.\n");
continue;
}

// call function to convert to english text
convert(inputNum);

}while(inputNum >0);
printf("\n");

}


void convert(int number)
{

if (number > 0 && number < 20){
printf(" %s ",ones[number]);

}else if (number / 1000 > 0) {
convert(number / 1000);
printf(" thousand ");
convert(number % 1000);

}else if (number / 100 > 0) {
convert(number / 100);
printf(" hundred ");
convert(number % 100);
}else if (number / 10 >= 2) {
printf(" %s ", tens[number / 10]);
convert(number % 10);
}

}

>How do I get floats max?

#include
// ...
float a = FLT_MAX;


>This gives me -1, which I'm assuming is because of the above stated about signed/unsigned types.
No, floats are floating point numbers.

en.wikipedia.org/wiki/IEEE_floating_point

read
en.wikipedia.org/wiki/Single-precision_floating-point_format

Uncomment your special case for zero and just add an else statement that checks for everything else. Change your do-while condition to while(inputNum>=0)

unsigned int max = -1; is more conventional.

Floats aren't represented like integers. They are represented as scientific notation. I think you might be able to programmatically get the max by filling a float with all ones, then XORing the most significant bit to 0.

It's likely still implementation defined so would better help you.

Do

if(!inputNum) //Equivalent to inputNum == 0
{
printf("zero");
break;
}

SOURCE WHEN

Thanks. I had this before. I'm just an idiot and kept entering zero instead of 0 for the prompt.

need to keep prompting until negative number.

Why am I such a fag?

Do you use Functional Programming?

Maybe you should stop sucking so much cock?

?

Still waiting

I am a certified Functional Programming™ user, in fact. Why, is that an issue?

I wrote a filesorting script but it bugs out when it runs into any kind of unusual unicode character.

Is this something I should bother fixing?

we need new op pics

also, can you guys answer this question. preferably in java or c or c++

Ew

Considering that the whole world (outside of japan) relies on UTF-8 encoding, yes, you should fix it.

The world would be a better place if programming was never invented.

I would like to say that no, I will not do your fucking homework.

how the fuck am I supposed to know the size of the array?
I hope it's a stack array.

a[0] = a[(float) sizeof(a) - sizeof(a[0])] * 2;

i did it, as shown by the green marker covering the answer. but i want to know what you guys would do

a[0] = 2 * a[-1]
toplel c fags gon be suicide watch

>implying we'll fall for your Jewish tricks

"Computers were a mistake" - Allen Turning

They were.

>(float) sizeof(a) - sizeof(a[0])
What the fuck are you even doing?

a[-1]? im sorry but you seem to be missing something

at first i thought about doing
a[0] = 2 * a[sizeof(a) - ((float) sizeof(a) / sizeof(a[0]))];
but i changed my mind

>how the fuck am I supposed to know the size of the array?

In intelligent languages (NOT C) the length of the array is stored.

why are you casting the index to float

>what is python

that's valid code in C as well btw
it just does something different

/dpt/

/ Dumb Programming Tards/

sizeof(a) / sizeof(a[0]) - 1

>posting the ribbit frog
go back

>C accepts a negative number as an index

WHY

oh yeah post what you're working on then, tough guy

Experimenting with parsing JSON.
protected void onCreate(Bundle savedInstanceState) {

//Set up activity, usual stuff

json = LoadJSON();
PopulateList();
}
private void PopulateList() {
JSONArray jsonArray = null;
try{
JSONObject jsonObject = new JSONObject(json);
jsonArray = jsonObject.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++){
JSONObject obj = jsonArray.getJSONObject(i);
String name = obj.getString("title");
String description = obj.getString("description");
String upc = obj.getString("upc");
String ean = obj.getString("ean");
ProductItem productItem = new ProductItem(name, description, upc, ean, null, null);
adapter.add(productItem);
}

} catch (JSONException e){
e.printStackTrace();
}
}
String LoadJSON() {
BufferedReader in = null;
try {
StringBuilder buf = new StringBuilder();
InputStream is = this.getAssets().open("TestJSON.json");
in = new BufferedReader(new InputStreamReader(is));
String str;
while ( (str = in.readLine()) != null ) {
buf.append(str);
}
in.close();
return buf.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}

Does mine work? I wanna know.

a[0] = a[sizeof(a) - sizeof(a[0])] * 2;

because arr[idx] is just syntactic sugar for *(arr+idx) where idx can be a negative number.
here's an example: ridiculousfish.com/blog/posts/old-age-and-treachery.html

No. Take uint16_t a[4]. 8 - 2 = 6, out of range.

Reading this literally makes me physically sick.

public class Product
{
public string name;
public string description;
public string upc;
public string ean;

public Product(string n, string d, string u, string e)
{
name = n;
description = d;
upc = u;
ean = e;
}

public static List LoadFromJson(string path)
{
return JsonConvert.DeserializeObject(File.ReadAllText(path));
}
}

okay ill go back here

im not working on anything

/dpt/

/ Depressed Puny Trimjobs /

it only takes java code

I'm using Java, though. It doesn't have C# one-liners for a lot of stuff.

How do I use SQL in C on OSX?

I've downloaded unixodbc and it's linked yet when I gcc -o x x.c i get the error
fatal error: 'sql.h' file not found

use sqlite you retard

Thank god for C-SHARTing in mart.

cheers nigga saved me the headache

Hey OSGTP, I can't seem to put 2 and 2 together on this one.

Why on earth is there such a difference in execution time here?

Am I being dense and missing something obvious?

Ah right, figured it out.

I just sent in an application for a job which I was supposed to send in my salary requirements but forgot to do so in my initial application email and I had to send it in separately as a separate email.

Am I stupid/autistic for worrying if this will affect my chances? Either way, someone kill me, I feel horrible right now.

giv address pls, ill hire someone

>hiring from Sup Forums

Seriously, why would anyone do this? All we post are interview-tier stuff that gets met with pajeet-tier code.

I'd be saving people from NEEThood.

I'll post it when it's reasonably feature-complete.

Right now it drags the entire database into memory on every page reload.

Holy crap, why? That is really inefficient.

I moved to the Bay Area and I doubt you would want to hire me unless you're looking for entry level people.

That is really inefficient.
I think that's the reason why. Most people don't want to share code they know is low-quality.

I'll be adding page offsets in a bit, calm down.

Artificial intelligence design of novel antenna shapes.

Genetic algorithms?

Pls post pics user kun

Isn't this just fine?
a[0] = 2 * a[sizeof(a) - 1]

>implying sizeof gives array length all the time

Just started using pro-font. I don't know whether I love it or hate it, yet. Anybody else using it?

It doesn't at all 100%. You have to divide the sizeof of the array by its first element to get the length accurately.

i guess

in java just replace 'sizeof' with 'a.length'

Java already looks disgusting enough, why must you people actively make it look even more disgusting?

Now try doing that after having passed the """""""""""array"""""""""" to a function.

>java

What languages should be learned in order to avoid the shitstorm of Pajeets?

>>java

D

scheme

Even though I know you're a microcuck, what you wrote is practically indistinguishable from Java, with the only difference I can spot being "bool".

I honestly don't think you can avoid Pajeets, especially if you're at a larger company.

Just learn how to understand Pajeet English already.

haskell
you can avoid anyone really, you'll have no friends

The lack of try/catch everywhere should be a good indicator.

import System.Environment (getArgs)
import Data.Bits

main = getArgs >>= pcross . read . head
where pcross = mapM_ putStrLn . cross

cross n = half ++ [space (length half) ++ "*"] ++ reverse half
where make v = flip (++) [" "] . takeWhile (/=" ") $ iterate (init . tail) (space v)
padding = zipWith (\x y -> space x ++ embrace y) [0..]
embrace = (++"*") . ('*':)
space j = replicate j ' '
half = padding (make $ (n.|.1) - 2)

Newbie question. Im going through some books, building mostly basic console command programs using Dev c++. Can i get the computer to run these programs from the console itself? Like without opening them in dev? There's no real reason to im just wondering.

Hello my name Pajeet I expert Java programer.

yes

That's interesting, thanks.

Kindly do the needful and update status of customer . Regards, Raj Sripanasakanlandakapoor

Wrongo dood

so inefficient
try cross 9000

First person on DPT actually taking some fucking initiative. Good on ya

I think it looks cool

lmao this is unreadable

Who wouldn't pass a size parameter when you need it and you're passing an array? I never claimed that sizeof(array) / sizeof(array[0]) will work everywhere, just the notion that sizeof(array) will not return the size of the array all the time, when the size of the element in an array is not 1 byte exactly or you are working with a pointer. Read the damn post again.

You hasklel idiots fell for the same trap that the sepples community did (pic related)

That is why lisp will always be superior to hasklel

"ECC in workstation is better!", they say.
but life has taught me that there always a give and take. what goes up, must come down.

tl;dr
are there any CONS to ECC memory vs non-ECC when all else is the same?

asking specifically for beefy workstations, heavy IDEs and emulating android, running VMs, compiling huge programs.

Why the hell are you asking that in the programming thread?

Do you
A.) plan to run your computer for a year or more?
B.) plan to be running code that could potentially cost you millions of dollars or kill people?
C.) plan to be operating you computer in space and/ or a high radiation environment?
If you answered no to all of these, you don't need ECC RAM.