问:
Shutting down twisted server
I have a twisted ServerFactory that I am using to push jobs off to clients. The protocol contains a queue that holds all of the jobs. Once this queue is exhausted if a client requests a new job, the server will disconnect the client. Eventually this will leave no clients connected and the server will be ready to shut down.

My question is this:

Is there a generally accepted best practice for shutting down a ServerFactory once it has completed its work?

I know that for clients the best practice is to use twisted.internet.task.react to connect and handle the loss of connection, thus closing the parent process. But I'm not sure if that is the case for a server as well.

Currently this is how I handle shutting down:

```<code>from twisted.application import internet, service
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
from twisted.protocols.basic import LineReceiver

class ServerProtocol(LineReceiver):
    """Twisted Protocol for sending and receiving lines of bytes."""
    clients = []
    logger = logging.getLogger('launcher.Launcher.RunServer')

    def connectionMade(self) -> None:
        """When a connection is made add the client to the clients list."""
        self.clients.append(self)

    def lineReceived(self, line: bytes) -> None:
        """Whenver a line is received send work to the sending client.

        Parameters
        ----------
        line
            The message received from a client.

        """
        msg = 'Received: ' + line.decode('utf-8') + ' from ' +\
            self.transport.hostname
        self.logger.info(msg)
        if not self.queue.empty():
            run = self.queue.get()
            run_bytes = bytes(run, 'utf-8')
            self.logger.info('Sending run bytes to %s',
                             self.transport.hostname)
            self.sendLine(run_bytes)
        else:
            self.clients.remove(self)
            self.transport.loseConnection()
            if not self.clients:
                self.logger.info('Shutting down RunServer')
                self.reactor.stop()

class RunServer(object):
    """Class for containing twisted server components.

    Parameters
    ----------
    workers
        List of workers that will serve as clients.
    queue
        Queue of runs to execute.

    Attributes
    ----------
    factory
        Twisted ServerFactory for producing protocols.

    """
    def __init__(self, queue: Queue) -> None:
        self.factory = ServerFactory()
        self.factory.protocol = ServerProtocol
        self.factory.protocol.queue = queue
        self.factory.protocol.reactor = reactor

    def start(self) -> None:
        """Start the server and thereby the execution of runs."""
        self.factory.protocol.reactor.listenTCP(80, self.factory)
        self.factory.protocol.reactor.run()
</code>```

As you can see I am storing the reactor in self.factory.protocol.reactor and using reactor.stop once all of the jobs have been exhausted and clients have disconnected.

I'm pretty sure I have read before that this is not the accepted pattern for running clients and I assume the same goes for servers, but I have yet to see a good example.

答:
I have to credit an acquaintance with this one.

There is absolutely no need for the RunServer class. Subclassing ServerFactory and placing the logic from RunServer.__init__ into the subclasses __init__ will allow the same behavior with better control. Then you can just define a main method and use react as it is described in the documentation (twisted.internet.task.react)

Here is the updated code:

```<code>from twisted.internet.defer import Deferred
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
from twisted.protocols.basic import LineReceiver

class QueueingProtocol(LineReceiver):
    def connectionMade(self) -> None:
        self.factory.connectionMade()

    def connectionLost(self, reason) -> None:
        self.factory.connectionLost(reason)

    def lineReceived(self, line: bytes) -> None:
        msg = 'Received: ' + line.decode('utf-8') + ' from ' +\
            self.transport.hostname
        self.logger.info(msg)
        if self.factory.empty():
            self.transport.lostConnection()
        else:
            run = self.factory.get()
            run_bytes = bytes(run, 'utf-8')
            self.logger.info('Sending run bytes to %s',
                             self.transport.hostname)
            self.sendLine(run_bytes)

class QueueingFactory(ServerFactory):
    protocol = QueueingProtocol

    def __init__(self, queue) -> None:
        self.queue = queue
        self.connections = 0
        self.queueHandled = Deferred()

    def connectionMade(self) -> None:
        self.connections += 1

    def empty(self):
        return self.queue.empty()

    def get(self):
        return self.queue.get()

    def connectionLost(self, reason) -> None:
        self.connections -= 1
        if self.connections == 0 and self.empty():
            self.queueHandled.callback("done")

def main(reactor, queue):
    factory = QueueingFactory(queue)
    reactor.listenTCP(80, factory)
    return factory.queueHandled
</code>```

Then you can just import main where you need it and call react(main, [some_queue])

Title: Shutting down twisted server

Body:
I have a twisted ServerFactory that I am using to push jobs off to clients. The protocol contains a queue that holds all of the jobs. Once this queue is exhausted if a client requests a new job, the server will disconnect the client. Eventually this will leave no clients connected and the server will be ready to shut down.

My question is this:

Is there a generally accepted best practice for shutting down a ServerFactory once it has completed its work?

I know that for clients the best practice is to use twisted.internet.task.react to connect and handle the loss of connection, thus closing the parent process. But I'm not sure if that is the case for a server as well.

Currently this is how I handle shutting down:

from twisted.application import internet, service
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
from twisted.protocols.basic import LineReceiver

class ServerProtocol(LineReceiver):
    """Twisted Protocol for sending and receiving lines of bytes."""
    clients = []
    logger = logging.getLogger('launcher.Launcher.RunServer')

    def connectionMade(self) -> None:
        """When a connection is made add the client to the clients list."""
        self.clients.append(self)

    def lineReceived(self, line: bytes) -> None:
        """Whenver a line is received send work to the sending client.

        Parameters
        ----------
        line
            The message received from a client.

        """
        msg = 'Received: ' + line.decode('utf-8') + ' from ' +\
            self.transport.hostname
        self.logger.info(msg)
        if not self.queue.empty():
            run = self.queue.get()
            run_bytes = bytes(run, 'utf-8')
            self.logger.info('Sending run bytes to %s',
                             self.transport.hostname)
            self.sendLine(run_bytes)
        else:
            self.clients.remove(self)
            self.transport.loseConnection()
            if not self.clients:
                self.logger.info('Shutting down RunServer')
                self.reactor.stop()

class RunServer(object):
    """Class for containing twisted server components.

    Parameters
    ----------
    workers
        List of workers that will serve as clients.
    queue
        Queue of runs to execute.

    Attributes
    ----------
    factory
        Twisted ServerFactory for producing protocols.

    """
    def __init__(self, queue: Queue) -> None:
        self.factory = ServerFactory()
        self.factory.protocol = ServerProtocol
        self.factory.protocol.queue = queue
        self.factory.protocol.reactor = reactor

    def start(self) -> None:
        """Start the server and thereby the execution of runs."""
        self.factory.protocol.reactor.listenTCP(80, self.factory)
        self.factory.protocol.reactor.run()

As you can see I am storing the reactor in self.factory.protocol.reactor and using reactor.stop once all of the jobs have been exhausted and clients have disconnected.

I'm pretty sure I have read before that this is not the accepted pattern for running clients and I assume the same goes for servers, but I have yet to see a good example.

Body:
I have to credit an acquaintance with this one.

There is absolutely no need for the RunServer class. Subclassing ServerFactory and placing the logic from RunServer.__init__ into the subclasses __init__ will allow the same behavior with better control. Then you can just define a main method and use react as it is described in the documentation (twisted.internet.task.react)

Here is the updated code:

from twisted.internet.defer import Deferred
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
from twisted.protocols.basic import LineReceiver

class QueueingProtocol(LineReceiver):
    def connectionMade(self) -> None:
        self.factory.connectionMade()

    def connectionLost(self, reason) -> None:
        self.factory.connectionLost(reason)

    def lineReceived(self, line: bytes) -> None:
        msg = 'Received: ' + line.decode('utf-8') + ' from ' +\
            self.transport.hostname
        self.logger.info(msg)
        if self.factory.empty():
            self.transport.lostConnection()
        else:
            run = self.factory.get()
            run_bytes = bytes(run, 'utf-8')
            self.logger.info('Sending run bytes to %s',
                             self.transport.hostname)
            self.sendLine(run_bytes)

class QueueingFactory(ServerFactory):
    protocol = QueueingProtocol

    def __init__(self, queue) -> None:
        self.queue = queue
        self.connections = 0
        self.queueHandled = Deferred()

    def connectionMade(self) -> None:
        self.connections += 1

    def empty(self):
        return self.queue.empty()

    def get(self):
        return self.queue.get()

    def connectionLost(self, reason) -> None:
        self.connections -= 1
        if self.connections == 0 and self.empty():
            self.queueHandled.callback("done")

def main(reactor, queue):
    factory = QueueingFactory(queue)
    reactor.listenTCP(80, factory)
    return factory.queueHandled

Then you can just import main where you need it and call react(main, [some_queue])


来源: stackexchange

问:
Joining 2 tables with limited joining conditions
I am quite new to SQL and I am trying to join two tables,

Table A:

```<code>ID  Amount    Bank
123  50        Barclays
123  50        tesco
123  50        HSBC
123  100       LLyods
123  200       MBNA
</code>```

Table B:

```<code>ID  Amount    Bank
123  50        aa
123  50        bb
123  50        cc
123  100       dd
123  200       ee
</code>```

Note that: in table B the bank name is the same as table A but it is written in a different format, so I can't join on this.

the script i am running is:

```<code>Select A.*, B.*
FROM TableA  A
Left Join TableB B
on A.ID = B.ID AND A.AMOUNT = B.AMOUNT
;
</code>```

The result i get is,

```<code>ID  Amount  Bank    ID  AMOUNT  BANK
123 50  Barclays    123 50      aa
123 50  Barclays    123 50      bb
123 50  Barclays    123 50      cc
123 50  tesco       123 50      aa
123 50  tesco       123 50      bb
123 50  tesco       123 50      cc
123 50  HSBC        123 50      aa
123 50  HSBC        123 50      bb
123 50  HSBC        123 50      cc
123 100 LLyods      123 100     dd
123 200 MBNA        123 200     ee
</code>```

what i want to get is,

```<code>ID  Amount  Bank    ID  AMOUNT  BANK
123 50  Barclays    123 50      aa
123 50  tesco       123 50      bb
123 50  HSBC        123 50      cc
123 100 LLyods      123 100     dd
123 200 MBNA        123 200     ee
</code>```

I get the issue is that it joining each row of table A to the rows of table B which meet the join conditions; unfortunately the table B has no other unique values that I can use as a join condition;

Can the community please see if you can think of something, I would very much appreciate it. Thank you :)

答:
To directly get the output you want, you can do this:

```<code>SELECT *
FROM TableA a
LEFT JOIN TableB b ON on A.ID = B.ID AND A.AMOUNT = B.AMOUNT
AND
(
    (a.Bank = 'Barclays' AND b.bank = 'aa') OR
    (a.Bank = 'tesco' AND b.bank = 'bb') OR
    (a.Bank = 'HSBC' AND b.bank = 'cc') OR
    (a.Bank = 'Lloyds' AND b.bank = 'dd') OR
    (a.Bank = 'MBNA' AND b.bank = 'ee')
)
</code>```

But this is ugly and not a great solution if you have hundreds of mappings.  It also assumes that (Bank, ID, Amount) is your PK for both tables.  The best way is to have a link/mapping table, like MorbidGnome suggested above and include that in your joins.

If you're not pulling any data from TableB (like in your example), then you can just use a CASE statement instead of joining to TableB:

```<code>SELECT a.*,
  CASE a.Bank
    WHEN 'Barclays' THEN 'aa'
    WHEN 'tesco' THEN 'bb'
    WHEN 'HSBC' THEN 'cc'
    WHEN 'Lloyds' THEN 'dd'
    WHEN 'MBNA' THEN 'ee'
  END AS Bank_B
FROM TableA
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am quite new to SQL and I am trying to join two tables,

Table A:

ID  Amount    Bank
123  50        Barclays
123  50        tesco
123  50        HSBC
123  100       LLyods
123  200       MBNA

Table B:

ID  Amount    Bank
123  50        aa
123  50        bb
123  50        cc
123  100       dd
123  200       ee

Note that: in table B the bank name is the same as table A but it is written in a different format, so I can't join on this.

the script i am running is:

Select A.*, B.*
FROM TableA  A
Left Join TableB B
on A.ID = B.ID AND A.AMOUNT = B.AMOUNT
;

The result i get is,

ID  Amount  Bank    ID  AMOUNT  BANK
123 50  Barclays    123 50      aa
123 50  Barclays    123 50      bb
123 50  Barclays    123 50      cc
123 50  tesco       123 50      aa
123 50  tesco       123 50      bb
123 50  tesco       123 50      cc
123 50  HSBC        123 50      aa
123 50  HSBC        123 50      bb
123 50  HSBC        123 50      cc
123 100 LLyods      123 100     dd
123 200 MBNA        123 200     ee

what i want to get is,

ID  Amount  Bank    ID  AMOUNT  BANK
123 50  Barclays    123 50      aa
123 50  tesco       123 50      bb
123 50  HSBC        123 50      cc
123 100 LLyods      123 100     dd
123 200 MBNA        123 200     ee

I get the issue is that it joining each row of table A to the rows of table B which meet the join conditions; unfortunately the table B has no other unique values that I can use as a join condition;

Can the community please see if you can think of something, I would very much appreciate it. Thank you :)

Body:
To directly get the output you want, you can do this:

SELECT *
FROM TableA a
LEFT JOIN TableB b ON on A.ID = B.ID AND A.AMOUNT = B.AMOUNT
AND
(
    (a.Bank = 'Barclays' AND b.bank = 'aa') OR
    (a.Bank = 'tesco' AND b.bank = 'bb') OR
    (a.Bank = 'HSBC' AND b.bank = 'cc') OR
    (a.Bank = 'Lloyds' AND b.bank = 'dd') OR
    (a.Bank = 'MBNA' AND b.bank = 'ee')
)

But this is ugly and not a great solution if you have hundreds of mappings.  It also assumes that (Bank, ID, Amount) is your PK for both tables.  The best way is to have a link/mapping table, like MorbidGnome suggested above and include that in your joins.

If you're not pulling any data from TableB (like in your example), then you can just use a CASE statement instead of joining to TableB:

SELECT a.*,
  CASE a.Bank
    WHEN 'Barclays' THEN 'aa'
    WHEN 'tesco' THEN 'bb'
    WHEN 'HSBC' THEN 'cc'
    WHEN 'Lloyds' THEN 'dd'
    WHEN 'MBNA' THEN 'ee'
  END AS Bank_B
FROM TableA


问:
Prevent absolute positioned nested ul from closing until hover outside
I have a nav menu and the last li contains a nested ul to show a dropdown menu. What I would like to do is display that nested menu on hover of the parent li and hide in when you hover away from the menu. The problem I'm facing now is that the menu starts glitching out as soon as you try to mouse into the sub-menu. I'm assuming this is because of the absolute position of the sub-menu. How can I resolve this?

$(function() {
  $('li.has-sub')
  .mouseover(function() {
  $(this).find('ul').slideDown();
 })
 .mouseout(function() {
  $(this).find('ul').slideUp();
 });
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>ul {
  list-style-type:none;
  padding:0 30px;
}
ul.nav {
  border:1px solid black;
}
ul.nav > li {
  display:inline-block;
  line-height:50px;
  margin-left:30px;
}
  ul.nav > li:first-child {
    margin-left:0;
  }
  ul.nav > li > ul {
    display:none;
    position:absolute;
    border:1px solid black;
  }</code>```

Link One

Link Two

Link Three

    Link Four

Sub Link One

Sub Link Two

Sub Link Three

```

答:
You are missing the .stop() method:

$(function() {
  $('li.has-sub').mouseover(function() {
    $(this).find('ul').stop().slideDown();
  })
  .mouseout(function() {
    $(this).find('ul').stop().slideUp();
  });
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>ul {
  list-style-type:none;
  padding:0 30px;
}

ul.nav {
  border:1px solid black;
}

ul.nav > li {
  display:inline-block;
  line-height:50px;
  margin-left:30px;
}

ul.nav > li:first-child {
  margin-left:0;
}

ul.nav > li > ul {
  display:none;
  position:absolute;
  border:1px solid black;
}</code>```

Link One

Link Two

Link Three

    Link Four

Sub Link One

Sub Link Two

Sub Link Three

```

Body:
I have a nav menu and the last li contains a nested ul to show a dropdown menu. What I would like to do is display that nested menu on hover of the parent li and hide in when you hover away from the menu. The problem I'm facing now is that the menu starts glitching out as soon as you try to mouse into the sub-menu. I'm assuming this is because of the absolute position of the sub-menu. How can I resolve this?

$(function() {
  $('li.has-sub')
  .mouseover(function() {
  $(this).find('ul').slideDown();
 })
 .mouseout(function() {
  $(this).find('ul').slideUp();
 });
});

ul {
  list-style-type:none;
  padding:0 30px;
}
ul.nav {
  border:1px solid black;
}
ul.nav > li {
  display:inline-block;
  line-height:50px;
  margin-left:30px;
}
  ul.nav > li:first-child {
    margin-left:0;
  }
  ul.nav > li > ul {
    display:none;
    position:absolute;
    border:1px solid black;
  }

Link One

Link Two

Link Three

    Link Four

Sub Link One

Sub Link Two

Sub Link Three

Body:
You are missing the .stop() method:

$(function() {
  $('li.has-sub').mouseover(function() {
    $(this).find('ul').stop().slideDown();
  })
  .mouseout(function() {
    $(this).find('ul').stop().slideUp();
  });
});

ul {
  list-style-type:none;
  padding:0 30px;
}

ul.nav {
  border:1px solid black;
}

ul.nav > li {
  display:inline-block;
  line-height:50px;
  margin-left:30px;
}

ul.nav > li:first-child {
  margin-left:0;
}

ul.nav > li > ul {
  display:none;
  position:absolute;
  border:1px solid black;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<ul class="nav">
  <li>Link One</li>
  <li>Link Two</li>
  <li>Link Three</li>
  <li class="has-sub">
    Link Four
    <ul>
      <li>Sub Link One</li>
      <li>Sub Link Two</li>
      <li>Sub Link Three</li>
    </ul>
  </li>
</ul>


问:
Sum of each row and column in 2D array (C)
I want to get the sum of each row and column of an array and print them one by one in C. I done half of work but I can't progress any more. There it is my code:

```<code>int n,m;
void sum_row_column(int array[n][m],int r,int c,int i,int j)
{
int sum_of_column1=0;
int sum_of_row1;

for(j=0,i=0;i<r;i++)
{
    sum_of_column1=sum_of_column1+array[i][j];
    if(i==r-1)
    {
        printf("\nSum of %d.column: %d\n",j+1,sum_of_column1);
        j=j+1;
    }
}

for(i=0,j=0;j<r;j++)
{
    sum_of_row1=sum_of_row1+array[i][j];
    if(j=c-1)
    {
        printf("\nSum of %d.row: %d\n",j+1,sum_of_row1);
        i=i+1;
    }
}
</code>```

As you can see it prints just first row's sum and column's sum. I thought if I add

```<code>i=0;
</code>```

after

```<code>printf("\nSum of %d.column: %d\n",j+1,sum_of_column1);
j=j+1
</code>```

line, it can move second column and sum it too. But when I add

```<code>i=0;
</code>```

the program go into infinite loop without any errors.
This code is in the header but don't worry in the rest of the code there aren't any mistake.

答:
Suggested code for the task

You have:

```<code>int n,m;
void sum_row_column(int array[n][m],int r,int c,int i,int j)
{
</code>```

Although this compiles, it is poorly-defined code, and is unnecessarily subject to failure if the global variables n and m are not set correctly.  There is no need for that level of coupling, and if you do use that level of coupling, the variables r and c are superfluous. You should be using:

```<code>void print_sum_rows_cols(int r, int c, int array[r][c])
{
</code>```

This allows the code to be used to print any shape of matrix using VLA (variable length array) notations.  The variables n and m should be unnecessary; the parameters i and j seem to be pointless too since you ignore the values passed to the function, setting both to 0 at the start of the loops.

Summing the columns is simple:

```<code>for (int col = 0; col < c; col++)
{
     int colsum = 0;
     for (int row = 0; row < r; row++)
         colsum += array[row][col];
     printf("Sum for col %d = %d\n", col, colsum);
}
</code>```

Summing the rows is equally straight-forward:

```<code>for (int row = 0; row < r; row++)
{
     int rowsum = 0;
     for (int col = 0; col < c; col++)
         rowsum += array[row][col];
     printf("Sum for row %d = %d\n", row, rowsum);
}
</code>```

Assembling an MCVE (Minimal, Complete, Verifiable Example):

```<code>#include <stdio.h>

static void print_sum_rows_cols(int r, int c, int array[r][c])
{
    for (int col = 0; col < c; col++)
    {
        int colsum = 0;
        for (int row = 0; row < r; row++)
            colsum += array[row][col];
        printf("Sum for col %d = %d\n", col, colsum);
    }
    for (int row = 0; row < r; row++)
    {
        int rowsum = 0;
        for (int col = 0; col < c; col++)
            rowsum += array[row][col];
        printf("Sum for row %d = %d\n", row, rowsum);
    }
}

static void dump_matrix(const char *tag, int rows, int cols, int matrix[rows][cols])
{
    printf("%s (%dx%d):\n", tag, rows, cols);
    for (int r = 0; r < rows; r++)
    {
        for (int c = 0; c < cols; c++)
            printf("%3d", matrix[r][c]);
        putchar('\n');
    }
}

int main(void)
{
    int a1[3][4] =
    {
        { 68, 78, 50, 46, },
        { 64, 12, 47,  1, },
        { 86, 10, 84, 62, },
    };
    int a2[5][3] =
    {
        {  4, 30, 19, },
        { 79, 58, 20, },
        { 95, 12, 24, },
        { 20, 37, 72, },
        { 17,  0, 53, },
    };

    dump_matrix("A1", 3, 4, a1);
    print_sum_rows_cols(3, 4, a1);

    dump_matrix("A2", 5, 3, a2);
    print_sum_rows_cols(5, 3, a2);

    return 0;
}
</code>```

The code in the (renamed) print_sum_rows_cols() function maintains the question's variable names, though they aren't the names I'd use in my own code.  (For those, see the "Analysis of another answer" section.)

And the output:

```<code>A1 (3x4):
 68 78 50 46
 64 12 47  1
 86 10 84 62
Sum for col 0 = 218
Sum for col 1 = 100
Sum for col 2 = 181
Sum for col 3 = 109
Sum for row 0 = 242
Sum for row 1 = 124
Sum for row 2 = 242
A2 (5x3):
  4 30 19
 79 58 20
 95 12 24
 20 37 72
 17  0 53
Sum for col 0 = 215
Sum for col 1 = 137
Sum for col 2 = 188
Sum for row 0 = 53
Sum for row 1 = 157
Sum for row 2 = 131
Sum for row 3 = 129
Sum for row 4 = 70
</code>```

Note that this prints the inputs so that the outputs can be checked manually against the inputs.  This is a useful technique in debugging.

Deconstructing an alternative answer

In an answer (revision 1), Jozeph has shown code which, it is claimed, works.  When indented in an orthodox format, the code is:

```<code>int n;
int m;

void sum_row_column(int array[n][m], int r, int c, int i, int j)
{
    int sumOfColumn = 0;
    int sumOfRow = 0;
    printf("\n");
    for (i = 0; i < r; i++)
    {
        sumOfRow = 0;
        for (j = 0; j < c; j++)
        {
            sumOfRow += array[i][j];
        }
        printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
    }
    printf("\n");
    for (j = 0; j < r; j++)
    {
        sumOfColumn = 0;
        for (i = 0; i < c; i++)
        {
            sumOfColumn += array[i][j];
        }
        printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
    }
}
</code>```

There are multiple problems with this code, some already identified but repeated in a marginally different form here:

The size of the matrix is identified by the values in the file scope (global) variables n and m.

The size of the matrix is also identified by the parameters r and c.

The values in the parameters i and j are unused; they're just a peculiar way of defining two local loop variables.

Assuming it is possible to assert(n == r && m == c);, the first pair of nested loops (which sum the rows) is OK.

Assuming it is possible to assert(n == r && m == c && n == m): (square matrix), the second pair of nested loop (which sum the columns) is OK, but it is mostly by accident rather than design.

However, if the global variables are not in sync with the parameters, then the calculations in the first pair of nested loops are incorrect because the loops use the size rxc but the function assumes the array has size mxn.

Similarly, if the global variables are not in sync with the parameters, or if the matrix is not square, the calculations in the second pair of nested loops are incorrect.  It doesn't even produce one 'column sum' for each column.

Here is an adaptation of my original answer to include the proposed answer (shown above) with some debug (read-only) printing added.  It also includes a minor variant of my original proposed function — the variables are renamed to suit my prejudices (short names for loop variables, longer names for function parameters, etc), plus the debug printing code.  The code also prints row sums before column sums to match the proposed answer's sequence, and it identifies the rows starting at row 1, column 1 instead of row 0, column 0.

There's also a 'bogus' variant of my answer (bogus_sum_rows_cols()) that uses the n and m variables to size the array; it produces the wrong answers when n and m are not in synchrony with r and c.  There's also a 'bogus' variant of the proposed answer (bogus_sum_row_column()) which does at least sum columns correctly if the array size in r and c matches both n and m.

```<code>/* SO 47719-9719 - Abuse of VLA definitions (and notations) */
#include <stdio.h>

static int debug = 0;

// Original answer (renamed variables, reordered results, and print row/col + 1)
static void print_sum_rows_cols(int rows, int cols, int array[rows][cols])
{
    for (int r = 0; r < rows; r++)
    {
        int rowsum = 0;
        for (int c = 0; c < cols; c++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            rowsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for row %d = %d\n", r + 1, rowsum);
    }
    putchar('\n');
    for (int c = 0; c < cols; c++)
    {
        int colsum = 0;
        for (int r = 0; r < rows; r++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            colsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for col %d = %d\n", c + 1, colsum);
    }
}

static int n;   // Rows
static int m;   // Columns

// Adapted print_sum_rows_cols with size from n, m
// Using n, m is unnecessary coupling (and can lead to erroneous results)
static void bogus_sum_rows_cols(int array[n][m], int rows, int cols)
{
    for (int r = 0; r < rows; r++)
    {
        int rowsum = 0;
        for (int c = 0; c < cols; c++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            rowsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for row %d = %d\n", r, rowsum);
    }
    putchar('\n');
    for (int c = 0; c < cols; c++)
    {
        int colsum = 0;
        for (int r = 0; r < rows; r++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            colsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for col %d = %d\n", c, colsum);
    }
}

// Original answer from OP - bogus results (debug printing added).
// Using n, m is unnecessary coupling (and can lead to erroneous results)
// Using i, j as arguments is bogus; the values passed in are ignored
// The 'sum column' loops are completely bogus.  The outer loop should
// iterate over columns [0..c) and the inner loop over rows [0..r).
// See print_sum_rows_cols() for the correct (minimal) interface.
static void sum_row_column(int array[n][m], int r, int c, int i, int j)
{
    int sumOfColumn = 0;
    int sumOfRow = 0;
    printf("\n");
    for (i = 0; i < r; i++)
    {
        sumOfRow = 0;
        for (j = 0; j < c; j++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfRow += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
    }
    printf("\n");
    for (j = 0; j < r; j++)
    {
        sumOfColumn = 0;
        for (i = 0; i < c; i++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfColumn += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
    }
}

// Semi-fixed answer from OP - bogus results (debug printing added).
// Using n, m is unnecessary coupling (and can lead to erroneous results)
// Using i, j as arguments is bogus; the values passed in are ignored
// The 'sum column' loops are completely bogus.  The outer loop should
// iterate over columns [0..c) and the inner loop over rows [0..r).
// See print_sum_rows_cols() for the correct (minimal) interface.
static void bogus_sum_row_column(int array[n][m], int r, int c, int i, int j)
{
    int sumOfColumn = 0;
    int sumOfRow = 0;
    printf("\n");
    for (i = 0; i < r; i++)
    {
        sumOfRow = 0;
        for (j = 0; j < c; j++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfRow += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
    }
    printf("\n");
    for (j = 0; j < c; j++)     // c, not r
    {
        sumOfColumn = 0;
        for (i = 0; i < r; i++) // r, not c
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfColumn += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
    }
}

static void dump_matrix(const char *tag, int rows, int cols, int matrix[rows][cols])
{
    printf("Matrix %s (%dx%d):\n", tag, rows, cols);
    for (int r = 0; r < rows; r++)
    {
        for (int c = 0; c < cols; c++)
            printf("%3d", matrix[r][c]);
        putchar('\n');
    }
}

static void test_sequence(int v_debug, int v_n, int v_m, const char *tag,
                          int rows, int cols, int matrix[rows][cols])
{
    debug = v_debug;
    n = v_n;
    m = v_m;
    dump_matrix(tag, rows, cols, matrix);
    printf("\nprint_sum_rows_cols():\n");
    print_sum_rows_cols(rows, cols, matrix);
    printf("\nbogus_sum_rows_cols() - (n = %d, m = %d):\n", n, m);
    bogus_sum_rows_cols(matrix, rows, cols);
    printf("\nsum_row_column()(n = %d, m = %d):\n", n, m);
    sum_row_column(matrix, rows, cols, -1, -1);
    printf("\nbogus_sum_row_column()(n = %d, m = %d):\n", n, m);
    bogus_sum_row_column(matrix, rows, cols, -1, -1);
    putchar('\n');
}

static void test_matrix_summation(const char *tag, int rows, int cols, int matrix[rows][cols])
{
    test_sequence(1,    2,    2, tag, rows, cols, matrix);
    test_sequence(0, rows, cols, tag, rows, cols, matrix);
}

int main(void)
{
    int a1[3][4] =
    {
        { 68, 78, 50, 46, },
        { 64, 12, 47,  1, },
        { 86, 10, 84, 62, },
    };
    int a2[5][3] =
    {
        {  4, 30, 19, },
        { 79, 58, 20, },
        { 95, 12, 24, },
        { 20, 37, 72, },
        { 17,  0, 53, },
    };
    int a3[3][3] =
    {
        { 96, 84, 13, },
        { 63, 29, 80, },
        { 97, 98, 48, },
    };

    test_matrix_summation("A1", 3, 4, a1);
    test_matrix_summation("A2", 5, 3, a2);
    test_matrix_summation("A3", 3, 3, a3);

    return 0;
}
</code>```

The output from the code shown is:

```<code>Matrix A1 (3x4):
 68 78 50 46
 64 12 47  1
 86 10 84 62

print_sum_rows_cols():
   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum for row 1 = 242
   a[1][0] = 64   a[1][1] = 12   a[1][2] = 47   a[1][3] = 1
Sum for row 2 = 124
   a[2][0] = 86   a[2][1] = 10   a[2][2] = 84   a[2][3] = 62
Sum for row 3 = 242

   a[0][0] = 68   a[1][0] = 64   a[2][0] = 86
Sum for col 1 = 218
   a[0][1] = 78   a[1][1] = 12   a[2][1] = 10
Sum for col 2 = 100
   a[0][2] = 50   a[1][2] = 47   a[2][2] = 84
Sum for col 3 = 181
   a[0][3] = 46   a[1][3] = 1   a[2][3] = 62
Sum for col 4 = 109

bogus_sum_rows_cols() - (n = 2, m = 2):
   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum for row 0 = 242
   a[1][0] = 50   a[1][1] = 46   a[1][2] = 64   a[1][3] = 12
Sum for row 1 = 172
   a[2][0] = 64   a[2][1] = 12   a[2][2] = 47   a[2][3] = 1
Sum for row 2 = 124

   a[0][0] = 68   a[1][0] = 50   a[2][0] = 64
Sum for col 0 = 182
   a[0][1] = 78   a[1][1] = 46   a[2][1] = 12
Sum for col 1 = 136
   a[0][2] = 50   a[1][2] = 64   a[2][2] = 47
Sum for col 2 = 161
   a[0][3] = 46   a[1][3] = 12   a[2][3] = 1
Sum for col 3 = 59

sum_row_column()(n = 2, m = 2):

   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum of 1.row=242
   a[1][0] = 50   a[1][1] = 46   a[1][2] = 64   a[1][3] = 12
Sum of 2.row=172
   a[2][0] = 64   a[2][1] = 12   a[2][2] = 47   a[2][3] = 1
Sum of 3.row=124

   a[0][0] = 68   a[1][0] = 50   a[2][0] = 64   a[3][0] = 47
Sum of 1.column=229
   a[0][1] = 78   a[1][1] = 46   a[2][1] = 12   a[3][1] = 1
Sum of 2.column=137
   a[0][2] = 50   a[1][2] = 64   a[2][2] = 47   a[3][2] = 86
Sum of 3.column=247

bogus_sum_row_column()(n = 2, m = 2):

   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum of 1.row=242
   a[1][0] = 50   a[1][1] = 46   a[1][2] = 64   a[1][3] = 12
Sum of 2.row=172
   a[2][0] = 64   a[2][1] = 12   a[2][2] = 47   a[2][3] = 1
Sum of 3.row=124

   a[0][0] = 68   a[1][0] = 50   a[2][0] = 64
Sum of 1.column=182
   a[0][1] = 78   a[1][1] = 46   a[2][1] = 12
Sum of 2.column=136
   a[0][2] = 50   a[1][2] = 64   a[2][2] = 47
Sum of 3.column=161
   a[0][3] = 46   a[1][3] = 12   a[2][3] = 1
Sum of 4.column=59

Matrix A1 (3x4):
 68 78 50 46
 64 12 47  1
 86 10 84 62

print_sum_rows_cols():
Sum for row 1 = 242
Sum for row 2 = 124
Sum for row 3 = 242

Sum for col 1 = 218
Sum for col 2 = 100
Sum for col 3 = 181
Sum for col 4 = 109

bogus_sum_rows_cols() - (n = 3, m = 4):
Sum for row 0 = 242
Sum for row 1 = 124
Sum for row 2 = 242

Sum for col 0 = 218
Sum for col 1 = 100
Sum for col 2 = 181
Sum for col 3 = 109

sum_row_column()(n = 3, m = 4):

Sum of 1.row=242
Sum of 2.row=124
Sum of 3.row=242

Sum of 1.column=222
Sum of 2.column=130
Sum of 3.column=200

bogus_sum_row_column()(n = 3, m = 4):

Sum of 1.row=242
Sum of 2.row=124
Sum of 3.row=242

Sum of 1.column=218
Sum of 2.column=100
Sum of 3.column=181
Sum of 4.column=109

Matrix A2 (5x3):
  4 30 19
 79 58 20
 95 12 24
 20 37 72
 17  0 53

print_sum_rows_cols():
   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum for row 1 = 53
   a[1][0] = 79   a[1][1] = 58   a[1][2] = 20
Sum for row 2 = 157
   a[2][0] = 95   a[2][1] = 12   a[2][2] = 24
Sum for row 3 = 131
   a[3][0] = 20   a[3][1] = 37   a[3][2] = 72
Sum for row 4 = 129
   a[4][0] = 17   a[4][1] = 0   a[4][2] = 53
Sum for row 5 = 70

   a[0][0] = 4   a[1][0] = 79   a[2][0] = 95   a[3][0] = 20   a[4][0] = 17
Sum for col 1 = 215
   a[0][1] = 30   a[1][1] = 58   a[2][1] = 12   a[3][1] = 37   a[4][1] = 0
Sum for col 2 = 137
   a[0][2] = 19   a[1][2] = 20   a[2][2] = 24   a[3][2] = 72   a[4][2] = 53
Sum for col 3 = 188

bogus_sum_rows_cols() - (n = 2, m = 2):
   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum for row 0 = 53
   a[1][0] = 19   a[1][1] = 79   a[1][2] = 58
Sum for row 1 = 156
   a[2][0] = 58   a[2][1] = 20   a[2][2] = 95
Sum for row 2 = 173
   a[3][0] = 95   a[3][1] = 12   a[3][2] = 24
Sum for row 3 = 131
   a[4][0] = 24   a[4][1] = 20   a[4][2] = 37
Sum for row 4 = 81

   a[0][0] = 4   a[1][0] = 19   a[2][0] = 58   a[3][0] = 95   a[4][0] = 24
Sum for col 0 = 200
   a[0][1] = 30   a[1][1] = 79   a[2][1] = 20   a[3][1] = 12   a[4][1] = 20
Sum for col 1 = 161
   a[0][2] = 19   a[1][2] = 58   a[2][2] = 95   a[3][2] = 24   a[4][2] = 37
Sum for col 2 = 233

sum_row_column()(n = 2, m = 2):

   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum of 1.row=53
   a[1][0] = 19   a[1][1] = 79   a[1][2] = 58
Sum of 2.row=156
   a[2][0] = 58   a[2][1] = 20   a[2][2] = 95
Sum of 3.row=173
   a[3][0] = 95   a[3][1] = 12   a[3][2] = 24
Sum of 4.row=131
   a[4][0] = 24   a[4][1] = 20   a[4][2] = 37
Sum of 5.row=81

   a[0][0] = 4   a[1][0] = 19   a[2][0] = 58
Sum of 1.column=81
   a[0][1] = 30   a[1][1] = 79   a[2][1] = 20
Sum of 2.column=129
   a[0][2] = 19   a[1][2] = 58   a[2][2] = 95
Sum of 3.column=172
   a[0][3] = 79   a[1][3] = 20   a[2][3] = 12
Sum of 4.column=111
   a[0][4] = 58   a[1][4] = 95   a[2][4] = 24
Sum of 5.column=177

bogus_sum_row_column()(n = 2, m = 2):

   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum of 1.row=53
   a[1][0] = 19   a[1][1] = 79   a[1][2] = 58
Sum of 2.row=156
   a[2][0] = 58   a[2][1] = 20   a[2][2] = 95
Sum of 3.row=173
   a[3][0] = 95   a[3][1] = 12   a[3][2] = 24
Sum of 4.row=131
   a[4][0] = 24   a[4][1] = 20   a[4][2] = 37
Sum of 5.row=81

   a[0][0] = 4   a[1][0] = 19   a[2][0] = 58   a[3][0] = 95   a[4][0] = 24
Sum of 1.column=200
   a[0][1] = 30   a[1][1] = 79   a[2][1] = 20   a[3][1] = 12   a[4][1] = 20
Sum of 2.column=161
   a[0][2] = 19   a[1][2] = 58   a[2][2] = 95   a[3][2] = 24   a[4][2] = 37
Sum of 3.column=233

Matrix A2 (5x3):
  4 30 19
 79 58 20
 95 12 24
 20 37 72
 17  0 53

print_sum_rows_cols():
Sum for row 1 = 53
Sum for row 2 = 157
Sum for row 3 = 131
Sum for row 4 = 129
Sum for row 5 = 70

Sum for col 1 = 215
Sum for col 2 = 137
Sum for col 3 = 188

bogus_sum_rows_cols() - (n = 5, m = 3):
Sum for row 0 = 53
Sum for row 1 = 157
Sum for row 2 = 131
Sum for row 3 = 129
Sum for row 4 = 70

Sum for col 0 = 215
Sum for col 1 = 137
Sum for col 2 = 188

sum_row_column()(n = 5, m = 3):

Sum of 1.row=53
Sum of 2.row=157
Sum of 3.row=131
Sum of 4.row=129
Sum of 5.row=70

Sum of 1.column=178
Sum of 2.column=100
Sum of 3.column=63
Sum of 4.column=194
Sum of 5.column=107

bogus_sum_row_column()(n = 5, m = 3):

Sum of 1.row=53
Sum of 2.row=157
Sum of 3.row=131
Sum of 4.row=129
Sum of 5.row=70

Sum of 1.column=215
Sum of 2.column=137
Sum of 3.column=188

Matrix A3 (3x3):
 96 84 13
 63 29 80
 97 98 48

print_sum_rows_cols():
   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum for row 1 = 193
   a[1][0] = 63   a[1][1] = 29   a[1][2] = 80
Sum for row 2 = 172
   a[2][0] = 97   a[2][1] = 98   a[2][2] = 48
Sum for row 3 = 243

   a[0][0] = 96   a[1][0] = 63   a[2][0] = 97
Sum for col 1 = 256
   a[0][1] = 84   a[1][1] = 29   a[2][1] = 98
Sum for col 2 = 211
   a[0][2] = 13   a[1][2] = 80   a[2][2] = 48
Sum for col 3 = 141

bogus_sum_rows_cols() - (n = 2, m = 2):
   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum for row 0 = 193
   a[1][0] = 13   a[1][1] = 63   a[1][2] = 29
Sum for row 1 = 105
   a[2][0] = 29   a[2][1] = 80   a[2][2] = 97
Sum for row 2 = 206

   a[0][0] = 96   a[1][0] = 13   a[2][0] = 29
Sum for col 0 = 138
   a[0][1] = 84   a[1][1] = 63   a[2][1] = 80
Sum for col 1 = 227
   a[0][2] = 13   a[1][2] = 29   a[2][2] = 97
Sum for col 2 = 139

sum_row_column()(n = 2, m = 2):

   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum of 1.row=193
   a[1][0] = 13   a[1][1] = 63   a[1][2] = 29
Sum of 2.row=105
   a[2][0] = 29   a[2][1] = 80   a[2][2] = 97
Sum of 3.row=206

   a[0][0] = 96   a[1][0] = 13   a[2][0] = 29
Sum of 1.column=138
   a[0][1] = 84   a[1][1] = 63   a[2][1] = 80
Sum of 2.column=227
   a[0][2] = 13   a[1][2] = 29   a[2][2] = 97
Sum of 3.column=139

bogus_sum_row_column()(n = 2, m = 2):

   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum of 1.row=193
   a[1][0] = 13   a[1][1] = 63   a[1][2] = 29
Sum of 2.row=105
   a[2][0] = 29   a[2][1] = 80   a[2][2] = 97
Sum of 3.row=206

   a[0][0] = 96   a[1][0] = 13   a[2][0] = 29
Sum of 1.column=138
   a[0][1] = 84   a[1][1] = 63   a[2][1] = 80
Sum of 2.column=227
   a[0][2] = 13   a[1][2] = 29   a[2][2] = 97
Sum of 3.column=139

Matrix A3 (3x3):
 96 84 13
 63 29 80
 97 98 48

print_sum_rows_cols():
Sum for row 1 = 193
Sum for row 2 = 172
Sum for row 3 = 243

Sum for col 1 = 256
Sum for col 2 = 211
Sum for col 3 = 141

bogus_sum_rows_cols() - (n = 3, m = 3):
Sum for row 0 = 193
Sum for row 1 = 172
Sum for row 2 = 243

Sum for col 0 = 256
Sum for col 1 = 211
Sum for col 2 = 141

sum_row_column()(n = 3, m = 3):

Sum of 1.row=193
Sum of 2.row=172
Sum of 3.row=243

Sum of 1.column=256
Sum of 2.column=211
Sum of 3.column=141

bogus_sum_row_column()(n = 3, m = 3):

Sum of 1.row=193
Sum of 2.row=172
Sum of 3.row=243

Sum of 1.column=256
Sum of 2.column=211
Sum of 3.column=141
</code>```

You can tweak when the debug is set on or off to get different amounts of output, but careful scrutiny of the results shows various discrepancies with the actual sums of rows and columns for the matrices defined in the main() program.

The fact that the proposed answer gets the 'right' answer on square matrices when the globals are synchronized with the parameters shows why it is important to do thorough testing.

If the code is only meant to handle square matrices, you'd not have both n and m (and you wouldn't need both r and c).  But you shouldn't tie the function to the global variables are all; you should define r and c (or just one of them if the matrix must be square).

This also shows why an MCVE (Minimal, Complete, Verifiable Example) is important.  The values in the variables n and m are not documented in the question or the proposed answer, so it was necessary to tease out the implications of what they represent.

Body:
I want to get the sum of each row and column of an array and print them one by one in C. I done half of work but I can't progress any more. There it is my code:

int n,m;
void sum_row_column(int array[n][m],int r,int c,int i,int j)
{
int sum_of_column1=0;
int sum_of_row1;

for(j=0,i=0;i<r;i++)
{
    sum_of_column1=sum_of_column1+array[i][j];
    if(i==r-1)
    {
        printf("\nSum of %d.column: %d\n",j+1,sum_of_column1);
        j=j+1;
    }
}

for(i=0,j=0;j<r;j++)
{
    sum_of_row1=sum_of_row1+array[i][j];
    if(j=c-1)
    {
        printf("\nSum of %d.row: %d\n",j+1,sum_of_row1);
        i=i+1;
    }
}

As you can see it prints just first row's sum and column's sum. I thought if I add

i=0;

after

printf("\nSum of %d.column: %d\n",j+1,sum_of_column1);
j=j+1

line, it can move second column and sum it too. But when I add

i=0;

the program go into infinite loop without any errors.
This code is in the header but don't worry in the rest of the code there aren't any mistake.

Body:
Suggested code for the task

You have:

int n,m;
void sum_row_column(int array[n][m],int r,int c,int i,int j)
{

Although this compiles, it is poorly-defined code, and is unnecessarily subject to failure if the global variables n and m are not set correctly.  There is no need for that level of coupling, and if you do use that level of coupling, the variables r and c are superfluous. You should be using:

void print_sum_rows_cols(int r, int c, int array[r][c])
{

This allows the code to be used to print any shape of matrix using VLA (variable length array) notations.  The variables n and m should be unnecessary; the parameters i and j seem to be pointless too since you ignore the values passed to the function, setting both to 0 at the start of the loops.

Summing the columns is simple:

for (int col = 0; col < c; col++)
{
     int colsum = 0;
     for (int row = 0; row < r; row++)
         colsum += array[row][col];
     printf("Sum for col %d = %d\n", col, colsum);
}

Summing the rows is equally straight-forward:

for (int row = 0; row < r; row++)
{
     int rowsum = 0;
     for (int col = 0; col < c; col++)
         rowsum += array[row][col];
     printf("Sum for row %d = %d\n", row, rowsum);
}

Assembling an MCVE (Minimal, Complete, Verifiable Example):

#include <stdio.h>

static void print_sum_rows_cols(int r, int c, int array[r][c])
{
    for (int col = 0; col < c; col++)
    {
        int colsum = 0;
        for (int row = 0; row < r; row++)
            colsum += array[row][col];
        printf("Sum for col %d = %d\n", col, colsum);
    }
    for (int row = 0; row < r; row++)
    {
        int rowsum = 0;
        for (int col = 0; col < c; col++)
            rowsum += array[row][col];
        printf("Sum for row %d = %d\n", row, rowsum);
    }
}

static void dump_matrix(const char *tag, int rows, int cols, int matrix[rows][cols])
{
    printf("%s (%dx%d):\n", tag, rows, cols);
    for (int r = 0; r < rows; r++)
    {
        for (int c = 0; c < cols; c++)
            printf("%3d", matrix[r][c]);
        putchar('\n');
    }
}

int main(void)
{
    int a1[3][4] =
    {
        { 68, 78, 50, 46, },
        { 64, 12, 47,  1, },
        { 86, 10, 84, 62, },
    };
    int a2[5][3] =
    {
        {  4, 30, 19, },
        { 79, 58, 20, },
        { 95, 12, 24, },
        { 20, 37, 72, },
        { 17,  0, 53, },
    };

    dump_matrix("A1", 3, 4, a1);
    print_sum_rows_cols(3, 4, a1);

    dump_matrix("A2", 5, 3, a2);
    print_sum_rows_cols(5, 3, a2);

    return 0;
}

The code in the (renamed) print_sum_rows_cols() function maintains the question's variable names, though they aren't the names I'd use in my own code.  (For those, see the "Analysis of another answer" section.)

And the output:

A1 (3x4):
 68 78 50 46
 64 12 47  1
 86 10 84 62
Sum for col 0 = 218
Sum for col 1 = 100
Sum for col 2 = 181
Sum for col 3 = 109
Sum for row 0 = 242
Sum for row 1 = 124
Sum for row 2 = 242
A2 (5x3):
  4 30 19
 79 58 20
 95 12 24
 20 37 72
 17  0 53
Sum for col 0 = 215
Sum for col 1 = 137
Sum for col 2 = 188
Sum for row 0 = 53
Sum for row 1 = 157
Sum for row 2 = 131
Sum for row 3 = 129
Sum for row 4 = 70

Note that this prints the inputs so that the outputs can be checked manually against the inputs.  This is a useful technique in debugging.

Deconstructing an alternative answer

In an answer (revision 1), Jozeph has shown code which, it is claimed, works.  When indented in an orthodox format, the code is:

int n;
int m;

void sum_row_column(int array[n][m], int r, int c, int i, int j)
{
    int sumOfColumn = 0;
    int sumOfRow = 0;
    printf("\n");
    for (i = 0; i < r; i++)
    {
        sumOfRow = 0;
        for (j = 0; j < c; j++)
        {
            sumOfRow += array[i][j];
        }
        printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
    }
    printf("\n");
    for (j = 0; j < r; j++)
    {
        sumOfColumn = 0;
        for (i = 0; i < c; i++)
        {
            sumOfColumn += array[i][j];
        }
        printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
    }
}

There are multiple problems with this code, some already identified but repeated in a marginally different form here:

The size of the matrix is identified by the values in the file scope (global) variables n and m.

The size of the matrix is also identified by the parameters r and c.

The values in the parameters i and j are unused; they're just a peculiar way of defining two local loop variables.

Assuming it is possible to assert(n == r && m == c);, the first pair of nested loops (which sum the rows) is OK.

Assuming it is possible to assert(n == r && m == c && n == m): (square matrix), the second pair of nested loop (which sum the columns) is OK, but it is mostly by accident rather than design.

However, if the global variables are not in sync with the parameters, then the calculations in the first pair of nested loops are incorrect because the loops use the size rxc but the function assumes the array has size mxn.

Similarly, if the global variables are not in sync with the parameters, or if the matrix is not square, the calculations in the second pair of nested loops are incorrect.  It doesn't even produce one 'column sum' for each column.

Here is an adaptation of my original answer to include the proposed answer (shown above) with some debug (read-only) printing added.  It also includes a minor variant of my original proposed function — the variables are renamed to suit my prejudices (short names for loop variables, longer names for function parameters, etc), plus the debug printing code.  The code also prints row sums before column sums to match the proposed answer's sequence, and it identifies the rows starting at row 1, column 1 instead of row 0, column 0.

There's also a 'bogus' variant of my answer (bogus_sum_rows_cols()) that uses the n and m variables to size the array; it produces the wrong answers when n and m are not in synchrony with r and c.  There's also a 'bogus' variant of the proposed answer (bogus_sum_row_column()) which does at least sum columns correctly if the array size in r and c matches both n and m.

/* SO 47719-9719 - Abuse of VLA definitions (and notations) */
#include <stdio.h>

static int debug = 0;

// Original answer (renamed variables, reordered results, and print row/col + 1)
static void print_sum_rows_cols(int rows, int cols, int array[rows][cols])
{
    for (int r = 0; r < rows; r++)
    {
        int rowsum = 0;
        for (int c = 0; c < cols; c++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            rowsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for row %d = %d\n", r + 1, rowsum);
    }
    putchar('\n');
    for (int c = 0; c < cols; c++)
    {
        int colsum = 0;
        for (int r = 0; r < rows; r++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            colsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for col %d = %d\n", c + 1, colsum);
    }
}

static int n;   // Rows
static int m;   // Columns

// Adapted print_sum_rows_cols with size from n, m
// Using n, m is unnecessary coupling (and can lead to erroneous results)
static void bogus_sum_rows_cols(int array[n][m], int rows, int cols)
{
    for (int r = 0; r < rows; r++)
    {
        int rowsum = 0;
        for (int c = 0; c < cols; c++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            rowsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for row %d = %d\n", r, rowsum);
    }
    putchar('\n');
    for (int c = 0; c < cols; c++)
    {
        int colsum = 0;
        for (int r = 0; r < rows; r++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", r, c, array[r][c]);
            colsum += array[r][c];
        }
        if (debug)
            putchar('\n');
        printf("Sum for col %d = %d\n", c, colsum);
    }
}

// Original answer from OP - bogus results (debug printing added).
// Using n, m is unnecessary coupling (and can lead to erroneous results)
// Using i, j as arguments is bogus; the values passed in are ignored
// The 'sum column' loops are completely bogus.  The outer loop should
// iterate over columns [0..c) and the inner loop over rows [0..r).
// See print_sum_rows_cols() for the correct (minimal) interface.
static void sum_row_column(int array[n][m], int r, int c, int i, int j)
{
    int sumOfColumn = 0;
    int sumOfRow = 0;
    printf("\n");
    for (i = 0; i < r; i++)
    {
        sumOfRow = 0;
        for (j = 0; j < c; j++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfRow += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
    }
    printf("\n");
    for (j = 0; j < r; j++)
    {
        sumOfColumn = 0;
        for (i = 0; i < c; i++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfColumn += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
    }
}

// Semi-fixed answer from OP - bogus results (debug printing added).
// Using n, m is unnecessary coupling (and can lead to erroneous results)
// Using i, j as arguments is bogus; the values passed in are ignored
// The 'sum column' loops are completely bogus.  The outer loop should
// iterate over columns [0..c) and the inner loop over rows [0..r).
// See print_sum_rows_cols() for the correct (minimal) interface.
static void bogus_sum_row_column(int array[n][m], int r, int c, int i, int j)
{
    int sumOfColumn = 0;
    int sumOfRow = 0;
    printf("\n");
    for (i = 0; i < r; i++)
    {
        sumOfRow = 0;
        for (j = 0; j < c; j++)
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfRow += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
    }
    printf("\n");
    for (j = 0; j < c; j++)     // c, not r
    {
        sumOfColumn = 0;
        for (i = 0; i < r; i++) // r, not c
        {
            if (debug)
                printf("   a[%d][%d] = %d", i, j, array[i][j]);
            sumOfColumn += array[i][j];
        }
        if (debug)
            putchar('\n');
        printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
    }
}

static void dump_matrix(const char *tag, int rows, int cols, int matrix[rows][cols])
{
    printf("Matrix %s (%dx%d):\n", tag, rows, cols);
    for (int r = 0; r < rows; r++)
    {
        for (int c = 0; c < cols; c++)
            printf("%3d", matrix[r][c]);
        putchar('\n');
    }
}

static void test_sequence(int v_debug, int v_n, int v_m, const char *tag,
                          int rows, int cols, int matrix[rows][cols])
{
    debug = v_debug;
    n = v_n;
    m = v_m;
    dump_matrix(tag, rows, cols, matrix);
    printf("\nprint_sum_rows_cols():\n");
    print_sum_rows_cols(rows, cols, matrix);
    printf("\nbogus_sum_rows_cols() - (n = %d, m = %d):\n", n, m);
    bogus_sum_rows_cols(matrix, rows, cols);
    printf("\nsum_row_column()(n = %d, m = %d):\n", n, m);
    sum_row_column(matrix, rows, cols, -1, -1);
    printf("\nbogus_sum_row_column()(n = %d, m = %d):\n", n, m);
    bogus_sum_row_column(matrix, rows, cols, -1, -1);
    putchar('\n');
}

static void test_matrix_summation(const char *tag, int rows, int cols, int matrix[rows][cols])
{
    test_sequence(1,    2,    2, tag, rows, cols, matrix);
    test_sequence(0, rows, cols, tag, rows, cols, matrix);
}

int main(void)
{
    int a1[3][4] =
    {
        { 68, 78, 50, 46, },
        { 64, 12, 47,  1, },
        { 86, 10, 84, 62, },
    };
    int a2[5][3] =
    {
        {  4, 30, 19, },
        { 79, 58, 20, },
        { 95, 12, 24, },
        { 20, 37, 72, },
        { 17,  0, 53, },
    };
    int a3[3][3] =
    {
        { 96, 84, 13, },
        { 63, 29, 80, },
        { 97, 98, 48, },
    };

    test_matrix_summation("A1", 3, 4, a1);
    test_matrix_summation("A2", 5, 3, a2);
    test_matrix_summation("A3", 3, 3, a3);

    return 0;
}

The output from the code shown is:

Matrix A1 (3x4):
 68 78 50 46
 64 12 47  1
 86 10 84 62

print_sum_rows_cols():
   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum for row 1 = 242
   a[1][0] = 64   a[1][1] = 12   a[1][2] = 47   a[1][3] = 1
Sum for row 2 = 124
   a[2][0] = 86   a[2][1] = 10   a[2][2] = 84   a[2][3] = 62
Sum for row 3 = 242

   a[0][0] = 68   a[1][0] = 64   a[2][0] = 86
Sum for col 1 = 218
   a[0][1] = 78   a[1][1] = 12   a[2][1] = 10
Sum for col 2 = 100
   a[0][2] = 50   a[1][2] = 47   a[2][2] = 84
Sum for col 3 = 181
   a[0][3] = 46   a[1][3] = 1   a[2][3] = 62
Sum for col 4 = 109

bogus_sum_rows_cols() - (n = 2, m = 2):
   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum for row 0 = 242
   a[1][0] = 50   a[1][1] = 46   a[1][2] = 64   a[1][3] = 12
Sum for row 1 = 172
   a[2][0] = 64   a[2][1] = 12   a[2][2] = 47   a[2][3] = 1
Sum for row 2 = 124

   a[0][0] = 68   a[1][0] = 50   a[2][0] = 64
Sum for col 0 = 182
   a[0][1] = 78   a[1][1] = 46   a[2][1] = 12
Sum for col 1 = 136
   a[0][2] = 50   a[1][2] = 64   a[2][2] = 47
Sum for col 2 = 161
   a[0][3] = 46   a[1][3] = 12   a[2][3] = 1
Sum for col 3 = 59

sum_row_column()(n = 2, m = 2):

   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum of 1.row=242
   a[1][0] = 50   a[1][1] = 46   a[1][2] = 64   a[1][3] = 12
Sum of 2.row=172
   a[2][0] = 64   a[2][1] = 12   a[2][2] = 47   a[2][3] = 1
Sum of 3.row=124

   a[0][0] = 68   a[1][0] = 50   a[2][0] = 64   a[3][0] = 47
Sum of 1.column=229
   a[0][1] = 78   a[1][1] = 46   a[2][1] = 12   a[3][1] = 1
Sum of 2.column=137
   a[0][2] = 50   a[1][2] = 64   a[2][2] = 47   a[3][2] = 86
Sum of 3.column=247

bogus_sum_row_column()(n = 2, m = 2):

   a[0][0] = 68   a[0][1] = 78   a[0][2] = 50   a[0][3] = 46
Sum of 1.row=242
   a[1][0] = 50   a[1][1] = 46   a[1][2] = 64   a[1][3] = 12
Sum of 2.row=172
   a[2][0] = 64   a[2][1] = 12   a[2][2] = 47   a[2][3] = 1
Sum of 3.row=124

   a[0][0] = 68   a[1][0] = 50   a[2][0] = 64
Sum of 1.column=182
   a[0][1] = 78   a[1][1] = 46   a[2][1] = 12
Sum of 2.column=136
   a[0][2] = 50   a[1][2] = 64   a[2][2] = 47
Sum of 3.column=161
   a[0][3] = 46   a[1][3] = 12   a[2][3] = 1
Sum of 4.column=59

Matrix A1 (3x4):
 68 78 50 46
 64 12 47  1
 86 10 84 62

print_sum_rows_cols():
Sum for row 1 = 242
Sum for row 2 = 124
Sum for row 3 = 242

Sum for col 1 = 218
Sum for col 2 = 100
Sum for col 3 = 181
Sum for col 4 = 109

bogus_sum_rows_cols() - (n = 3, m = 4):
Sum for row 0 = 242
Sum for row 1 = 124
Sum for row 2 = 242

Sum for col 0 = 218
Sum for col 1 = 100
Sum for col 2 = 181
Sum for col 3 = 109

sum_row_column()(n = 3, m = 4):

Sum of 1.row=242
Sum of 2.row=124
Sum of 3.row=242

Sum of 1.column=222
Sum of 2.column=130
Sum of 3.column=200

bogus_sum_row_column()(n = 3, m = 4):

Sum of 1.row=242
Sum of 2.row=124
Sum of 3.row=242

Sum of 1.column=218
Sum of 2.column=100
Sum of 3.column=181
Sum of 4.column=109

Matrix A2 (5x3):
  4 30 19
 79 58 20
 95 12 24
 20 37 72
 17  0 53

print_sum_rows_cols():
   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum for row 1 = 53
   a[1][0] = 79   a[1][1] = 58   a[1][2] = 20
Sum for row 2 = 157
   a[2][0] = 95   a[2][1] = 12   a[2][2] = 24
Sum for row 3 = 131
   a[3][0] = 20   a[3][1] = 37   a[3][2] = 72
Sum for row 4 = 129
   a[4][0] = 17   a[4][1] = 0   a[4][2] = 53
Sum for row 5 = 70

   a[0][0] = 4   a[1][0] = 79   a[2][0] = 95   a[3][0] = 20   a[4][0] = 17
Sum for col 1 = 215
   a[0][1] = 30   a[1][1] = 58   a[2][1] = 12   a[3][1] = 37   a[4][1] = 0
Sum for col 2 = 137
   a[0][2] = 19   a[1][2] = 20   a[2][2] = 24   a[3][2] = 72   a[4][2] = 53
Sum for col 3 = 188

bogus_sum_rows_cols() - (n = 2, m = 2):
   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum for row 0 = 53
   a[1][0] = 19   a[1][1] = 79   a[1][2] = 58
Sum for row 1 = 156
   a[2][0] = 58   a[2][1] = 20   a[2][2] = 95
Sum for row 2 = 173
   a[3][0] = 95   a[3][1] = 12   a[3][2] = 24
Sum for row 3 = 131
   a[4][0] = 24   a[4][1] = 20   a[4][2] = 37
Sum for row 4 = 81

   a[0][0] = 4   a[1][0] = 19   a[2][0] = 58   a[3][0] = 95   a[4][0] = 24
Sum for col 0 = 200
   a[0][1] = 30   a[1][1] = 79   a[2][1] = 20   a[3][1] = 12   a[4][1] = 20
Sum for col 1 = 161
   a[0][2] = 19   a[1][2] = 58   a[2][2] = 95   a[3][2] = 24   a[4][2] = 37
Sum for col 2 = 233

sum_row_column()(n = 2, m = 2):

   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum of 1.row=53
   a[1][0] = 19   a[1][1] = 79   a[1][2] = 58
Sum of 2.row=156
   a[2][0] = 58   a[2][1] = 20   a[2][2] = 95
Sum of 3.row=173
   a[3][0] = 95   a[3][1] = 12   a[3][2] = 24
Sum of 4.row=131
   a[4][0] = 24   a[4][1] = 20   a[4][2] = 37
Sum of 5.row=81

   a[0][0] = 4   a[1][0] = 19   a[2][0] = 58
Sum of 1.column=81
   a[0][1] = 30   a[1][1] = 79   a[2][1] = 20
Sum of 2.column=129
   a[0][2] = 19   a[1][2] = 58   a[2][2] = 95
Sum of 3.column=172
   a[0][3] = 79   a[1][3] = 20   a[2][3] = 12
Sum of 4.column=111
   a[0][4] = 58   a[1][4] = 95   a[2][4] = 24
Sum of 5.column=177

bogus_sum_row_column()(n = 2, m = 2):

   a[0][0] = 4   a[0][1] = 30   a[0][2] = 19
Sum of 1.row=53
   a[1][0] = 19   a[1][1] = 79   a[1][2] = 58
Sum of 2.row=156
   a[2][0] = 58   a[2][1] = 20   a[2][2] = 95
Sum of 3.row=173
   a[3][0] = 95   a[3][1] = 12   a[3][2] = 24
Sum of 4.row=131
   a[4][0] = 24   a[4][1] = 20   a[4][2] = 37
Sum of 5.row=81

   a[0][0] = 4   a[1][0] = 19   a[2][0] = 58   a[3][0] = 95   a[4][0] = 24
Sum of 1.column=200
   a[0][1] = 30   a[1][1] = 79   a[2][1] = 20   a[3][1] = 12   a[4][1] = 20
Sum of 2.column=161
   a[0][2] = 19   a[1][2] = 58   a[2][2] = 95   a[3][2] = 24   a[4][2] = 37
Sum of 3.column=233

Matrix A2 (5x3):
  4 30 19
 79 58 20
 95 12 24
 20 37 72
 17  0 53

print_sum_rows_cols():
Sum for row 1 = 53
Sum for row 2 = 157
Sum for row 3 = 131
Sum for row 4 = 129
Sum for row 5 = 70

Sum for col 1 = 215
Sum for col 2 = 137
Sum for col 3 = 188

bogus_sum_rows_cols() - (n = 5, m = 3):
Sum for row 0 = 53
Sum for row 1 = 157
Sum for row 2 = 131
Sum for row 3 = 129
Sum for row 4 = 70

Sum for col 0 = 215
Sum for col 1 = 137
Sum for col 2 = 188

sum_row_column()(n = 5, m = 3):

Sum of 1.row=53
Sum of 2.row=157
Sum of 3.row=131
Sum of 4.row=129
Sum of 5.row=70

Sum of 1.column=178
Sum of 2.column=100
Sum of 3.column=63
Sum of 4.column=194
Sum of 5.column=107

bogus_sum_row_column()(n = 5, m = 3):

Sum of 1.row=53
Sum of 2.row=157
Sum of 3.row=131
Sum of 4.row=129
Sum of 5.row=70

Sum of 1.column=215
Sum of 2.column=137
Sum of 3.column=188

Matrix A3 (3x3):
 96 84 13
 63 29 80
 97 98 48

print_sum_rows_cols():
   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum for row 1 = 193
   a[1][0] = 63   a[1][1] = 29   a[1][2] = 80
Sum for row 2 = 172
   a[2][0] = 97   a[2][1] = 98   a[2][2] = 48
Sum for row 3 = 243

   a[0][0] = 96   a[1][0] = 63   a[2][0] = 97
Sum for col 1 = 256
   a[0][1] = 84   a[1][1] = 29   a[2][1] = 98
Sum for col 2 = 211
   a[0][2] = 13   a[1][2] = 80   a[2][2] = 48
Sum for col 3 = 141

bogus_sum_rows_cols() - (n = 2, m = 2):
   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum for row 0 = 193
   a[1][0] = 13   a[1][1] = 63   a[1][2] = 29
Sum for row 1 = 105
   a[2][0] = 29   a[2][1] = 80   a[2][2] = 97
Sum for row 2 = 206

   a[0][0] = 96   a[1][0] = 13   a[2][0] = 29
Sum for col 0 = 138
   a[0][1] = 84   a[1][1] = 63   a[2][1] = 80
Sum for col 1 = 227
   a[0][2] = 13   a[1][2] = 29   a[2][2] = 97
Sum for col 2 = 139

sum_row_column()(n = 2, m = 2):

   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum of 1.row=193
   a[1][0] = 13   a[1][1] = 63   a[1][2] = 29
Sum of 2.row=105
   a[2][0] = 29   a[2][1] = 80   a[2][2] = 97
Sum of 3.row=206

   a[0][0] = 96   a[1][0] = 13   a[2][0] = 29
Sum of 1.column=138
   a[0][1] = 84   a[1][1] = 63   a[2][1] = 80
Sum of 2.column=227
   a[0][2] = 13   a[1][2] = 29   a[2][2] = 97
Sum of 3.column=139

bogus_sum_row_column()(n = 2, m = 2):

   a[0][0] = 96   a[0][1] = 84   a[0][2] = 13
Sum of 1.row=193
   a[1][0] = 13   a[1][1] = 63   a[1][2] = 29
Sum of 2.row=105
   a[2][0] = 29   a[2][1] = 80   a[2][2] = 97
Sum of 3.row=206

   a[0][0] = 96   a[1][0] = 13   a[2][0] = 29
Sum of 1.column=138
   a[0][1] = 84   a[1][1] = 63   a[2][1] = 80
Sum of 2.column=227
   a[0][2] = 13   a[1][2] = 29   a[2][2] = 97
Sum of 3.column=139

Matrix A3 (3x3):
 96 84 13
 63 29 80
 97 98 48

print_sum_rows_cols():
Sum for row 1 = 193
Sum for row 2 = 172
Sum for row 3 = 243

Sum for col 1 = 256
Sum for col 2 = 211
Sum for col 3 = 141

bogus_sum_rows_cols() - (n = 3, m = 3):
Sum for row 0 = 193
Sum for row 1 = 172
Sum for row 2 = 243

Sum for col 0 = 256
Sum for col 1 = 211
Sum for col 2 = 141

sum_row_column()(n = 3, m = 3):

Sum of 1.row=193
Sum of 2.row=172
Sum of 3.row=243

Sum of 1.column=256
Sum of 2.column=211
Sum of 3.column=141

bogus_sum_row_column()(n = 3, m = 3):

Sum of 1.row=193
Sum of 2.row=172
Sum of 3.row=243

Sum of 1.column=256
Sum of 2.column=211
Sum of 3.column=141

You can tweak when the debug is set on or off to get different amounts of output, but careful scrutiny of the results shows various discrepancies with the actual sums of rows and columns for the matrices defined in the main() program.

The fact that the proposed answer gets the 'right' answer on square matrices when the globals are synchronized with the parameters shows why it is important to do thorough testing.

If the code is only meant to handle square matrices, you'd not have both n and m (and you wouldn't need both r and c).  But you shouldn't tie the function to the global variables are all; you should define r and c (or just one of them if the matrix must be square).

This also shows why an MCVE (Minimal, Complete, Verifiable Example) is important.  The values in the variables n and m are not documented in the question or the proposed answer, so it was necessary to tease out the implications of what they represent.


问:
Command Line Tools not working - OS X El Capitan, Sierra, High Sierra, Mojave
I just upgraded from Yosemite to El Capitan (and replicated the problem upgrading from El Capitan to Sierra), and when I try to type for example git status inside a terminal, I get the following error:

```<code>xcrun: error: invalid active developer path
 (/Library/Developer/CommandLineTools), missing xcrun at:
 /Library/Developer/CommandLineTools/usr/bin/xcrun
</code>```

I don't have Xcode installed, never did.
Anyone have a solution?

答:
Updated to High Sierra 10.13.2

xcode-select --install ALONE did not work for me.

Download X-code from app store

$xcode-select --install

a. May need to update after install using softwareupdate in command line.  $sudo softwareupdate -i "Command Line Tools (macOS High Sierra version 10.13) for Xcode-9.1"

$sudo xcodebuild -license

ContentLicense: CC BY-SA 4.0

Body:
I just upgraded from Yosemite to El Capitan (and replicated the problem upgrading from El Capitan to Sierra), and when I try to type for example git status inside a terminal, I get the following error:

xcrun: error: invalid active developer path
 (/Library/Developer/CommandLineTools), missing xcrun at:
 /Library/Developer/CommandLineTools/usr/bin/xcrun

I don't have Xcode installed, never did.
Anyone have a solution?


问:
Layout Problem in Android
I am fairly new to android and am having some problems with a layout. Below is an approximation of what I want the layout to look like. (I would like the list to be below the screen at first so that the user can scroll down to see it.) However my code as it currently stands makes all of the views on the left only take up a quarter the screen instead of half, as depicted, even though I have all widths set to fill_parent.

Also, this layout seems to mess up the coordinate system on my custom view. Normally this wouldn't be much of an issue, but in this case I am using that view to draw a picture and the picture ends up in the wrong place. Does anybody have any idea how to resolve these issues?

Here is my code:

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TableRow>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:orientation="vertical"
android:layout_width="fill_parent">
<TableRow>
 <TextView android:text="Resultant Force" android:id="@+id/resForceTitle"
  android:textSize="25dip" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:padding="3dip"
  android:gravity="center" android:layout_span="2" />
</TableRow>
<TableRow>
 <TextView android:id="@+id/magText" android:text="Magnitude (N) ="
  android:textSize="15dip" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:padding="3dip"
  android:gravity="center_vertical" android:layout_span="2" />
</TableRow>
<TableRow>
 <EditText android:id="@+id/magnitude" android:inputType="numberDecimal"
  android:layout_width="fill_parent" android:padding="3dip"
  android:layout_height="fill_parent" android:layout_span="2" />
</TableRow>
<TableRow>
 <TextView android:id="@+id/dirText" android:text="Angle (deg) ="
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:textSize="15dip" android:gravity="center_vertical"
  android:layout_span="2" />
</TableRow>
<TableRow>
 <EditText android:id="@+id/direction" android:inputType="numberDecimal"
  android:layout_height="fill_parent" android:padding="3dip"
  android:layout_width="fill_parent" android:layout_span="2" />
</TableRow>
<TableRow>
 <Button android:id="@+id/pushButton" android:text="Add Force"
  android:layout_height="fill_parent" android:padding="3dip"
  android:layout_width="fill_parent" />
 <Button android:id="@+id/clearButton" android:text="Clear"
  android:layout_height="fill_parent" android:padding="3dip"
  android:layout_width="fill_parent" />
</TableRow>
</TableLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<android.physicsengine.AxisDrawing
 android:id="@+id/image" android:layout_width="fill_parent"
 android:layout_height="fill_parent" />
</FrameLayout>
</TableRow>
</TableLayout>
<ListView android:id="@android:id/list" android:layout_height="wrap_content"
android:padding="3dip" android:layout_width="fill_parent"
android:clickable="false" />
<TextView android:id="@android:id/empty" android:text="Add Forces to List Components"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textSize="15dip" android:gravity="center_vertical" />
</LinearLayout>
</code>```

答:
From the look of your XML it looks like you misunderstand what fill_parent means. It means "be as big as my parent." Also, why are you using two nested TableLayouts? To divide the screen evenly in two you should use a horizontal LinearLayout and give each child (the TableLayout and your custom View) a width of 0dip and a layout_weight of 1:</p>

```<code><LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TableLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content">
            ...
    </TableLayout>
    <android.physicsengine.AxisDrawing
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content" />
</LinearLayout>
</code>```

ContentLicense: CC BY-SA 2.5

Title: Layout Problem in Android

Body:
I am fairly new to android and am having some problems with a layout. Below is an approximation of what I want the layout to look like. (I would like the list to be below the screen at first so that the user can scroll down to see it.) However my code as it currently stands makes all of the views on the left only take up a quarter the screen instead of half, as depicted, even though I have all widths set to fill_parent.

Also, this layout seems to mess up the coordinate system on my custom view. Normally this wouldn't be much of an issue, but in this case I am using that view to draw a picture and the picture ends up in the wrong place. Does anybody have any idea how to resolve these issues?

Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TableRow>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:orientation="vertical"
android:layout_width="fill_parent">
<TableRow>
 <TextView android:text="Resultant Force" android:id="@+id/resForceTitle"
  android:textSize="25dip" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:padding="3dip"
  android:gravity="center" android:layout_span="2" />
</TableRow>
<TableRow>
 <TextView android:id="@+id/magText" android:text="Magnitude (N) ="
  android:textSize="15dip" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:padding="3dip"
  android:gravity="center_vertical" android:layout_span="2" />
</TableRow>
<TableRow>
 <EditText android:id="@+id/magnitude" android:inputType="numberDecimal"
  android:layout_width="fill_parent" android:padding="3dip"
  android:layout_height="fill_parent" android:layout_span="2" />
</TableRow>
<TableRow>
 <TextView android:id="@+id/dirText" android:text="Angle (deg) ="
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:textSize="15dip" android:gravity="center_vertical"
  android:layout_span="2" />
</TableRow>
<TableRow>
 <EditText android:id="@+id/direction" android:inputType="numberDecimal"
  android:layout_height="fill_parent" android:padding="3dip"
  android:layout_width="fill_parent" android:layout_span="2" />
</TableRow>
<TableRow>
 <Button android:id="@+id/pushButton" android:text="Add Force"
  android:layout_height="fill_parent" android:padding="3dip"
  android:layout_width="fill_parent" />
 <Button android:id="@+id/clearButton" android:text="Clear"
  android:layout_height="fill_parent" android:padding="3dip"
  android:layout_width="fill_parent" />
</TableRow>
</TableLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<android.physicsengine.AxisDrawing
 android:id="@+id/image" android:layout_width="fill_parent"
 android:layout_height="fill_parent" />
</FrameLayout>
</TableRow>
</TableLayout>
<ListView android:id="@android:id/list" android:layout_height="wrap_content"
android:padding="3dip" android:layout_width="fill_parent"
android:clickable="false" />
<TextView android:id="@android:id/empty" android:text="Add Forces to List Components"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textSize="15dip" android:gravity="center_vertical" />
</LinearLayout>

Body:
From the look of your XML it looks like you misunderstand what fill_parent means. It means "be as big as my parent." Also, why are you using two nested TableLayouts? To divide the screen evenly in two you should use a horizontal LinearLayout and give each child (the TableLayout and your custom View) a width of 0dip and a layout_weight of 1:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TableLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content">
            ...
    </TableLayout>
    <android.physicsengine.AxisDrawing
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content" />
</LinearLayout>


问:
Combined nodes to a single one based on a common property
I'm trying to learn more about Neo4j. Is there a way to group nodes that have the same name/number/etc.?

In standard RDBMS one can use the "Group by" clause to combine specific values into one.  Have a look at the picture for a better understanding.

I'd like to combine these two nodes ("EE", "EE") into one, which has both sub-nodes.

Code for the image output:

```<code>match (A:Place)-[:`->`]-(B:Typ)
where A.name ='City1'
return A, B
</code>```

答:
There is no equivalent for SQL's GROUP BY clause in Cypher, as it is done implicitly. So whenever you use an aggregating function, such as count, sum, min or collect, the rest of the variables in the tuple are grouped implicitly.

```<code>MATCH (a:Place {name: 'City1'})-[:`->`]-(b:Typ)
RETURN a.name, count(b)
</code>```

However, it seems to me that you actually want to perform a transformation that combines parent nodes together (we could say that the nodes are "merged" together, but I would like to avoid that word, as there is a MERGE clause in Cypher with different semantics -- see @cybersam's answer for details).

Match for the required pattern.

Project to the property that will serve as a key for grouping and group.

Create a new parent node.

Create the name property to that node.

Add relationships to the new node.

Remove old parent nodes.

In practice, this could be implemented with a query like this:

```<code>MATCH (a:Place {name: 'City1'})-[:`->`]-(b:Typ)
WITH a.name AS name, collect(a) AS as, collect(b) AS bs
CREATE (new:Place {name: name})
WITH as, bs, new
UNWIND bs AS b
CREATE (new)-[:`->`]->(b)
WITH as
UNWIND as AS a
DETACH DELETE a
</code>```

While the query is quite complex, fortunately, it is easy to test on a toy data set:

```<code>CREATE
  (:Place {name: 'City1'})-[:`->`]->(:Typ {name: 'B1'}),
  (:Place {name: 'City1'})-[:`->`]->(:Typ {name: 'B2'})
</code>```

This results in:

And is combined to:

Body:
I'm trying to learn more about Neo4j. Is there a way to group nodes that have the same name/number/etc.?

In standard RDBMS one can use the "Group by" clause to combine specific values into one.  Have a look at the picture for a better understanding.

I'd like to combine these two nodes ("EE", "EE") into one, which has both sub-nodes.

Code for the image output:

match (A:Place)-[:`->`]-(B:Typ)
where A.name ='City1'
return A, B

Body:
There is no equivalent for SQL's GROUP BY clause in Cypher, as it is done implicitly. So whenever you use an aggregating function, such as count, sum, min or collect, the rest of the variables in the tuple are grouped implicitly.

MATCH (a:Place {name: 'City1'})-[:`->`]-(b:Typ)
RETURN a.name, count(b)

However, it seems to me that you actually want to perform a transformation that combines parent nodes together (we could say that the nodes are "merged" together, but I would like to avoid that word, as there is a MERGE clause in Cypher with different semantics -- see @cybersam's answer for details).

Match for the required pattern.

Project to the property that will serve as a key for grouping and group.

Create a new parent node.

Create the name property to that node.

Add relationships to the new node.

Remove old parent nodes.

In practice, this could be implemented with a query like this:

MATCH (a:Place {name: 'City1'})-[:`->`]-(b:Typ)
WITH a.name AS name, collect(a) AS as, collect(b) AS bs
CREATE (new:Place {name: name})
WITH as, bs, new
UNWIND bs AS b
CREATE (new)-[:`->`]->(b)
WITH as
UNWIND as AS a
DETACH DELETE a

While the query is quite complex, fortunately, it is easy to test on a toy data set:

CREATE
  (:Place {name: 'City1'})-[:`->`]->(:Typ {name: 'B1'}),
  (:Place {name: 'City1'})-[:`->`]->(:Typ {name: 'B2'})

This results in:

And is combined to:


问:
post params not being stored in Mongo db
I'm trying to build a simple blog with a MEAN stack and I'm currently setting up the back end. I'm testing my routes with Postman and for some reason, I can't save the title and body of a post in the DB.

My model:
models/posts/db.js

```<code>var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var PostSchema = new Schema ({
  title: { type: String },
  body: { type: String },
  date: { type: Date, default: Date.now }
});

module.exports = mongoose.model('Post', PostSchema);
</code>```

My controller: controllers/posts.index.js

```<code>var base = process.env.PWD;
var Post = require(base + '/models/posts/db.js')

var createPost = function(req, res) {
  var post = new Post(req.body)

  post.save(function(err, post) {
    if(err) { res.sendStatus(500, err); }
    res.json(post);
  })
}

var getPosts = function(req, res) {
  Post.find(function(err, posts) {
    if (err) { res.sendStatus(500, err); }
    res.json(posts);
  })
};

module.exports = {
  createPost,
  getPosts
}
</code>```

And here are my main routes in routes/index.js

```<code>router.get('/posts', posts.getPosts);
router.post('/posts/create', posts.createPost);

module.exports = router;
</code>```

And my main server is using a /api endpoint:

```<code>`app.use('/api', routes);`
</code>```

So in Postman, when I send a POST request to /api/posts/create with a post containing a title and a body, an empty post is stored. I get something like this inserted:

```<code>{
    "__v": 0,
    "_id": "5a29de91521f168eb9e1bcf2",
    "date": "2017-12-08T00:36:33.280Z"
}
</code>```

Any help would be appreciated.

答:
I figured it out, 2 problems:

The order of where you place body-parser is important, I wrote the line after setting my routes so it wasn't parsing anything.

I hadn't set up my Postman correctly, it was sending regular text instead of a JSON object. facepalm

Body:
I'm trying to build a simple blog with a MEAN stack and I'm currently setting up the back end. I'm testing my routes with Postman and for some reason, I can't save the title and body of a post in the DB.

My model:
models/posts/db.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var PostSchema = new Schema ({
  title: { type: String },
  body: { type: String },
  date: { type: Date, default: Date.now }
});

module.exports = mongoose.model('Post', PostSchema);

My controller: controllers/posts.index.js

var base = process.env.PWD;
var Post = require(base + '/models/posts/db.js')

var createPost = function(req, res) {
  var post = new Post(req.body)

  post.save(function(err, post) {
    if(err) { res.sendStatus(500, err); }
    res.json(post);
  })
}

var getPosts = function(req, res) {
  Post.find(function(err, posts) {
    if (err) { res.sendStatus(500, err); }
    res.json(posts);
  })
};

module.exports = {
  createPost,
  getPosts
}

And here are my main routes in routes/index.js

router.get('/posts', posts.getPosts);
router.post('/posts/create', posts.createPost);

module.exports = router;

And my main server is using a /api endpoint:

`app.use('/api', routes);`

So in Postman, when I send a POST request to /api/posts/create with a post containing a title and a body, an empty post is stored. I get something like this inserted:

{
    "__v": 0,
    "_id": "5a29de91521f168eb9e1bcf2",
    "date": "2017-12-08T00:36:33.280Z"
}

Any help would be appreciated.


问:
Can't log in to Google Apps Scripts
I'm using multiple Google accounts. In one of them (not default) I created Google Spreadsheet file and I want to create Script connected to it. Nothing complicated. But the problem is that after clicking Tools > Script Editor I'm being redirected to default user or I see this screen:

The same problem I have when trying to use: script.google.com

What can I do to enable Script editor?

答:
You can consider appending authuser=email to the URL to open the script with a specific Google account.

For example, script.google.com...?param=value&authuser=email@example.com

Title: Can't log in to Google Apps Scripts


问:
In RabbitMQ, how to handle the conflict between prefetch and 'redelivered'
Basically I have the similar issue as here:

http://rabbitmq.1065348.n5.nabble.com/Consumer-crash-redelivery-and-prefetch-td34103.html

I want to prefetch some messages for performance.
At the same time, if one message fails, I do want to give it a second chance (retry twice) and currently I use the 'redelivered' flag to implement this. If 'redelivered' is not set, I will re-queue the message, otherwise I will abandon the message.
This will cause a problem for those prefetched messages (not yet processed) if the consumer crashes as they have not been processed yet but the 'redelivered' flag will be set.

Is there any solution for this? Or any other better way to implement retry logic for the RabbitMQ message?
Thanks,

答:
Have you considered using a dead letter exchange?

Basically instead of re-queuing a failed message, you reject it.
And if you have a dead letter exchange configured you can setup a new flow for that rejected message, for example put it on another queue to which your process also subscribes to.

With such a mechanism, all messages will be processed at least twice, which seems to be your goal.


问:
VueJS slot in v-for
I want to make a grid component which accepts as slot additional column cell.

```<code><grid>
  <td slot="additional-column">...</td>
</grid>
</code>```

In the actual component:

```<code><template>
   <table>
     <div v-for="item in items">
       ...
       <slot name="additional-column"></slot>
     </div>
   </table>
</template>
</code>```

Unfortunately the slot starts repeating itself and this is something vuejs doesn't like.

Duplicate presence of slot "additional-column" found in the same render tree - this will likely cause render errors.

Does anybody know how can I deal with this issue?

Thanks in advance!

答:
This definitely seems to be your issue. You could do it this way too (as described here). See last paragraph before the subheading Destructuring.

Parent:

```<code><grid>
  <td :slot="['additional-column', item].join('-')" v-for="item in items">
  ...
  </td>
</grid>
</code>```

Child:

```<code><table>
    <div v-for="item in items">
        ...
        <slot :name="['additional-column', item].join('-')"></slot>
    </div>
</table>
</code>```

PS: I have NOT tried this out. If you have difficulties I could create a fiddle and share.

Title: VueJS slot in v-for

Body:
I want to make a grid component which accepts as slot additional column cell.

<grid>
  ...
</grid>

In the actual component:

<template>

       ...
       <slot name="additional-column"></slot>

</template>

Unfortunately the slot starts repeating itself and this is something vuejs doesn't like.

Duplicate presence of slot "additional-column" found in the same render tree - this will likely cause render errors.

Does anybody know how can I deal with this issue?

Thanks in advance!

Body:
This definitely seems to be your issue. You could do it this way too (as described here). See last paragraph before the subheading Destructuring.

Parent:

<grid>
  <td :slot="['additional-column', item].join('-')" v-for="item in items">
  ...
  </td>
</grid>

Child:

<table>
    <div v-for="item in items">
        ...
        <slot :name="['additional-column', item].join('-')"></slot>
    </div>
</table>

PS: I have NOT tried this out. If you have difficulties I could create a fiddle and share.


问:
Loop Failure in Google Sheets
I have a loop whose purpose is to iterate through a Google Sheet, which shall be identified as sheet, and treated as a two-dimensional array.

```<code>for (var i = 0; i < sheet.length; i++) {
  var currentDataset = sheet.getRange(i+1, 1);
  var currentData = currentDataset.getCell(1, 1).getValue();

  Logger.log(String(currentData));

  switch (String(currentData)) {
    case string:
      Logger.log("match");
      for (var ii = 0; ii < 16; ii++) {
        currentDataset.getCell(1, ii+1).setValue(data[ii]);
      }
      break;

    default:
      Logger.log("no match");
      break;
  }
}
</code>```

If the first cell, currentData, in the current row, currentDataset, according to i matches in a switch statement with the String value string, another loop would iterate to replace the appropriate values in the respective row with successiindeces of data, an array. If the current cell value does not match, the switch would default and break, allowing the loop to iterate again.

When the function is called, the loop begins to iterate through the sheet, defaulting on all the mismatches. However, when the loop reaches the match, it skips it. Here are what the logs look like:

```<code>[17-12-08 08:20:13:909 PST] Mismatch Value
[17-12-08 08:20:13:910 PST] default
*** THIS IS WHERE THE MATCH VALUE SHOULD APPEAR ***
[17-12-08 08:20:14:389 PST] Mismatch Value
[17-12-08 08:20:14:390 PST] default
</code>```

I rewrote the code above to make variables more readable as it was originally in GAS, please comment if you require more detailed code, or find it here (lines 51 - 62): https://github.com/organism/Scorecard-Builder/blob/master/src/scorecardBuilder.gs

答:
I think this is what you were trying to do:

```<code>function myfunction(){
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();//or whatever
  var rg=ss.getDataRange();
  var vA=rg.getValues();//gets all the data on the sheet
  for(var i=0;i<vA.length;i++){
    switch(typeof(vA[i][0])){
      case 'string':
        Logger.log('Match=%s',vA[i][0]);
        for(var j=0;j<16;j++){
          sh.getRange(i+1,j+1).setValue(vA[i][0])
        }
        break;
      default:
        Logger.log('No Match=%s',vA[i][0]);
        break;
    }
  }
}
</code>```

Spreadsheet before running:

Spreadsheet After Running:

My Logger Output:

If that's not what you were shooting for then I'm sorry to interject myself here.

Title: Loop Failure in Google Sheets

Body:
I have a loop whose purpose is to iterate through a Google Sheet, which shall be identified as sheet, and treated as a two-dimensional array.

for (var i = 0; i < sheet.length; i++) {
  var currentDataset = sheet.getRange(i+1, 1);
  var currentData = currentDataset.getCell(1, 1).getValue();

  Logger.log(String(currentData));

  switch (String(currentData)) {
    case string:
      Logger.log("match");
      for (var ii = 0; ii < 16; ii++) {
        currentDataset.getCell(1, ii+1).setValue(data[ii]);
      }
      break;

    default:
      Logger.log("no match");
      break;
  }
}

If the first cell, currentData, in the current row, currentDataset, according to i matches in a switch statement with the String value string, another loop would iterate to replace the appropriate values in the respective row with successiindeces of data, an array. If the current cell value does not match, the switch would default and break, allowing the loop to iterate again.

When the function is called, the loop begins to iterate through the sheet, defaulting on all the mismatches. However, when the loop reaches the match, it skips it. Here are what the logs look like:

[17-12-08 08:20:13:909 PST] Mismatch Value
[17-12-08 08:20:13:910 PST] default
*** THIS IS WHERE THE MATCH VALUE SHOULD APPEAR ***
[17-12-08 08:20:14:389 PST] Mismatch Value
[17-12-08 08:20:14:390 PST] default

I rewrote the code above to make variables more readable as it was originally in GAS, please comment if you require more detailed code, or find it here (lines 51 - 62): https://github.com/organism/Scorecard-Builder/blob/master/src/scorecardBuilder.gs

Body:
I think this is what you were trying to do:

function myfunction(){
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();//or whatever
  var rg=ss.getDataRange();
  var vA=rg.getValues();//gets all the data on the sheet
  for(var i=0;i<vA.length;i++){
    switch(typeof(vA[i][0])){
      case 'string':
        Logger.log('Match=%s',vA[i][0]);
        for(var j=0;j<16;j++){
          sh.getRange(i+1,j+1).setValue(vA[i][0])
        }
        break;
      default:
        Logger.log('No Match=%s',vA[i][0]);
        break;
    }
  }
}

Spreadsheet before running:

Spreadsheet After Running:

My Logger Output:

If that's not what you were shooting for then I'm sorry to interject myself here.


问:
Firebase Auth: Re-authenticate user who is using custom token
In android app the user is allowed to use Linkedin as signin option using Firebase Functions. User sends linkedin token to firebase function and as a result it receives AdminSdk generated Custom token.

Now as we know the token can be used for signin with
mAuth.signInWithCustomToken(mCustomToken). But I cannot find a way to use the custom token to generate AuthCredential.

There is OAuthProvider class which can generate AuthCredential but re-authentication fails.
getCredential(String providerId, String idToken, String accessToken)

Any solution to this problem?

答:
Unfortunately Firebase Auth does not offer a way to re-authenticate with a custom token. You can request this as a feature: https://firebase.google.com/support/contact/bugs-features/

Right now, you have to basically use signInWithCustomToken again. However, you will be signing out the original user and there is also a risk the user signs in with a different account. You will need to retain the original uid to confirm the new signed in user is the same one (has same uid). If the same user signs in again, you also have to get a new reference to the currentUser.


问:
How do I break out of this if?
I need to break out of the if statement when one of the for loops is used. But when I compile and run it, all three for loops give back info when I only need one. I know the answer is staring me in the face, but I just can't figure out what it is.</p>

```<code>if (filestat == 'S' || filestat == 's')
{

  for ( a = 0; a < 5000; a++)
  {
     taxableincome = grossincome - 5000 - (1000 * exemptions);
     taxrate = .15;
     taxAmount = taxableincome * taxrate;
     System.out.println("Your Taxpayer ID is " + taxid);
     System.out.println("Your taxable income is $" + taxableincome);
     System.out.println("Your tax rate is %" + taxrate);
     System.out.println("Your tax amount is $" + taxAmount);

     break;
  }

  for (a = 5000; a <= 20000; a++)
  {
     taxableincome = grossincome - 5000 - (1000 * exemptions);
     taxrate = .22;
     taxAmount = taxableincome * taxrate;
     System.out.println("Your Taxpayer ID is " + taxid);
     System.out.println("Your taxable income is $" + taxableincome);
     System.out.println("Your tax rate is %" + taxrate);
     System.out.println("Your tax amount is $" + taxAmount);

     break;
  }

  for (a = 20001; a >= 20001; a++)
  {
     taxableincome = grossincome - 5000 - (1000 * exemptions);
     taxrate = .31;
     taxAmount = taxableincome * taxrate;
     System.out.println("Your Taxpayer ID is " + taxid);
     System.out.println("Your taxable income is $" + taxableincome);
     System.out.println("Your tax rate is %" + taxrate);
     System.out.println("Your tax amount is $" + taxAmount);

     break;
  }

}
</code>```

答:
If you want to print the output for all possible a you can just delete the break statements. (But you'd have to provide an upper limit for the third loop.)

If you want to print the output only for one particular a you should use if instead of for.

```<code>if (filestat == 'S' || filestat == 's')
{
    if (a < 5000)
    {
        taxableincome = grossincome - 5000 - (1000 * exemptions);
        taxrate = .15;
        taxAmount = taxableincome * taxrate;
    }
    else if (a <= 20000)
    {
        taxableincome = grossincome - 5000 - (1000 * exemptions);
        taxrate = .22;
        taxAmount = taxableincome * taxrate;
    }
    else
    {
        taxableincome = grossincome - 5000 - (1000 * exemptions);
        taxrate = .31;
        taxAmount = taxableincome * taxrate;
    }
}
System.out.println("Your Taxpayer ID is " + taxid);
System.out.println("Your taxable income is $" + taxableincome);
System.out.println("Your tax rate is %" + taxrate);
System.out.println("Your tax amount is $" + taxAmount);
</code>```

Title: How do I break out of this if?

Body:
I need to break out of the if statement when one of the for loops is used. But when I compile and run it, all three for loops give back info when I only need one. I know the answer is staring me in the face, but I just can't figure out what it is.

if (filestat == 'S' || filestat == 's')
{

  for ( a = 0; a < 5000; a++)
  {
     taxableincome = grossincome - 5000 - (1000 * exemptions);
     taxrate = .15;
     taxAmount = taxableincome * taxrate;
     System.out.println("Your Taxpayer ID is " + taxid);
     System.out.println("Your taxable income is $" + taxableincome);
     System.out.println("Your tax rate is %" + taxrate);
     System.out.println("Your tax amount is $" + taxAmount);

     break;
  }

  for (a = 5000; a <= 20000; a++)
  {
     taxableincome = grossincome - 5000 - (1000 * exemptions);
     taxrate = .22;
     taxAmount = taxableincome * taxrate;
     System.out.println("Your Taxpayer ID is " + taxid);
     System.out.println("Your taxable income is $" + taxableincome);
     System.out.println("Your tax rate is %" + taxrate);
     System.out.println("Your tax amount is $" + taxAmount);

     break;
  }

  for (a = 20001; a >= 20001; a++)
  {
     taxableincome = grossincome - 5000 - (1000 * exemptions);
     taxrate = .31;
     taxAmount = taxableincome * taxrate;
     System.out.println("Your Taxpayer ID is " + taxid);
     System.out.println("Your taxable income is $" + taxableincome);
     System.out.println("Your tax rate is %" + taxrate);
     System.out.println("Your tax amount is $" + taxAmount);

     break;
  }

}

Body:
If you want to print the output for all possible a you can just delete the break statements. (But you'd have to provide an upper limit for the third loop.)

If you want to print the output only for one particular a you should use if instead of for.

if (filestat == 'S' || filestat == 's')
{
    if (a < 5000)
    {
        taxableincome = grossincome - 5000 - (1000 * exemptions);
        taxrate = .15;
        taxAmount = taxableincome * taxrate;
    }
    else if (a <= 20000)
    {
        taxableincome = grossincome - 5000 - (1000 * exemptions);
        taxrate = .22;
        taxAmount = taxableincome * taxrate;
    }
    else
    {
        taxableincome = grossincome - 5000 - (1000 * exemptions);
        taxrate = .31;
        taxAmount = taxableincome * taxrate;
    }
}
System.out.println("Your Taxpayer ID is " + taxid);
System.out.println("Your taxable income is $" + taxableincome);
System.out.println("Your tax rate is %" + taxrate);
System.out.println("Your tax amount is $" + taxAmount);