mercredi 27 juillet 2016

C program skipping digits 8 and 9 when incrementing

I am writing a program in C =

Blockquote function void multi_table(unsigned int xsize, unsigned int ysize) that prints a multiplication table on the screen that has numbers from 1 to 'xsize' on the x-axis, and numbers from 1 to 'ysize' on the y-axis, and products of these numbers in tabular format.

my code is like so:

void multi_table(unsigned int xsize, unsigned int ysize)
{
    for(unsigned int row = 1; row <= ysize; row++){
        unsigned int count = 0;
        for(unsigned int column = row; count < xsize; column+=row){
            printf(" %o ",column);
            count++;
        }
        printf("n");
}

and for some weird reason when I call the function

printf("n--- Multiplication table ---n");
multi_table(5,4);

I am getting this output:

--- Multiplication table ---
 1  2  3  4  5 
 2  4  6  10  12 
 3  6  11  14  17 
 4  10  14  20  24 

I am STUCK, please help

PHP MySQL article views count not working

In my blog, I want to count the articles views every time the page is loaded so I can make a chart of the top articles.

I'm using this code but something goes wrong.

If I put the first query in phpMyAdmin the query result is correct.

$readViewsCountSQL = "SELECT `view_count` FROM `andreaem`.`article` WHERE `article`.`slug` = '$articleSlug' LIMIT 1";
$readViewsCount = $DB_CON ->query($readViewsCountSQL); 
$readViewsCountResult = $readViewsCount->fetch(PDO::FETCH_ASSOC);

function updateVCount ($current) {
    $count = $current ++;
    return $count;
}
$addViewsCount = updateVCount($readViewsCountResult);
var_dump($addViewsCount); //This return the correct value
$updateViewsCount = "UPDATE `andreaem`.`article` SET  `view_count` =  '$addViewsCount' WHERE  `article`.`slug` = '$articleSlug'";
$DB_CON ->query($updateViewsCount);

In the mySQL logs the query was executed successfully but something goes wrong.

$DB_CON is the PDO connection and working in other queries

How to override the default watchers in ng-bind?

I'm trying to make a log-in section on a website. Before the user is logged in, I want an area to say "Login". After the user is logged in, I want the area to display the username. The user logs in by pressing a button.

The HTML has something like this:

<a href="login.html ng-bind="userID">Login</a>

<body ng-app="loginButton" ng-controller="loginControl">
    <form ng-submit="enterSite()">
        <p>User ID <input type="text" ng-model="userID"></p>
        <input type="submit" Value="Log In">
    </form>
</body>

and then the JS has something like this:

var appButton = angular.module("loginButton", []);

appButton.controller("loginControl", ["$scope", "$window", function($scope, $window){
    $scope.enterSite = function(){
        if (/*they are a valid user*/){
            $scope.apply();
    }
}]);

how to pass on value to an integer pointer

#include<stdio.h>

int main ()
{
    int *ip;
    printf("Enter a no n");
    scanf("%d",ip);
    printf("ip=%d",*ip);
}

Above is my program and when I run it following is output

./a.out 
Enter a no 
10
Segmentation fault

I checked in gdb line 6 is problem which is

scanf("%d",ip);

So I infer that ip is a pointer to integer and %d expects an address value. While I am trying to pass on an integer to the value specified by ip so I think that is wrong. But what is the correct thing to do in the above situation. I want to use scan and assign an integer value to the address pointed to by ip (which in my case is missing).

Uncaught SyntaxError: Invalid or unexpected token

I have a razor syntax like this:

   foreach(var item in model)
 {
<td><a href ="#"  onclick="Getinfo(@item.email);" >6/16/2016 2:02:29 AM</a>  </td>
 }

My javascript that recieves the request goes like this:

<script type="text/javascript" src="~/Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
    function Getinfo(elem) {
        var email = document.getElementById(elem).innerHTML;
    }
</script>

When clicking on the href link, I get the following error in the console of the browser:

"Uncaught SyntaxError: Invalid or unexpected token",

and this part is underlined:

    **</a>  </td>**

I am a beginner so I get stuck in syntax a lot. If it is that then please help me out.

I can´t print a string that was read using the "gets" function [duplicate]

This question already has an answer here:

It works if I read the string value first and then the int value. I tried use function gets instead of scanf because gets lets me read more than one word in the same line.

I also tried with fgets but it has the same problem.

I'm using cygwin 32 bit compiler version 2.874. I using codeblocks ide 13.12.

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

int main() {
    int i;
    char s[10];

    printf("Value int:n");
    scanf("%d",&i);
    printf("%dn",i);

    printf("Value string:");
    fflush(stdin);
    gets(s);
    printf("%sn",s);

    getchar();
    return 0;
}

ReactDOMServer.renderToStaticMarkup on client side to prevent xss

In our react.js based codebase, we use an external library which accepts raw html, and we had xss issues due to code like:

'<div title="' + dangerousTitle + ' ">' + dangerousText + '</div>';

I need to come up with a policy for the team and it seemed possible to use:

ReactDOMServer.renderToStaticMarkup(
     <div title={dangerousTitle}>
         {dangerousText}
     </div>
);

On the client side code. However, in react documentation, it is explicitly stated that renderToStaticMarkup is for server side use.

Assuming we know what we are doing, does anybody have any argument against above use?

PS: we considered _.escape, _.template with <%-, `` template strings with escaping function, above seemed the best fit since the team is already used to react templates more than anything else.