Hi all,
Is there any way to print a matrix's elements using a simple printf ?
what I want as result is for example:
if mat ={0,1,2,3}
result must be: "0123".
I tried this code:
/*************** *************** *************** *************** ***/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define size 10
int main (void)
{
// Declaration
int i = 0;
int mat[size]= {0,0,0,0};
char convert[size]= {0,0,0,0};
for (i=0;i<4;i++)
{
mat[i]=mat[i]+i+1;
printf("mat[%d]=%d\n",i,mat[i]);
// Convert int to string
sprintf(convert ,"%s",(char *)&mat[i]);
// concatenate matrix's elements
// strcat(convert[i+1],convert[i]);
}
printf ("Matrix is equal to %s\n",(char *)&convert);
return (0);
}
/*************** *************** *************** *************** ***/
After execution I get this
$ ./matrix
mat[0]=1
mat[1]=2
mat[2]=3
mat[3]=4
Matrix is equal to
If I activate the line :
strcat(convert[i+1],convert[i]);
I get
matrix.c: In function ‘main’:
matrix.c:23: warning: passing argument 1 of ‘strcat’ makes pointer
from integer without a cast
matrix.c:23: warning: passing argument 2 of ‘strcat’ makes pointer
from integer without a cast
And when executing :
./matrix
mat[0]=1
Segmentation fault.
Jul 21 '08
12 3122
rahul wrote:
That looks slick. Better than calling realloc/malloc(which makes system
calls to underlying OS on most of the platforms; quiet expansive)
Doesn't one /want/ (many) realloc calls to be quietly expansive?
--
'It changed the future .. and it changed us.' /Babylon 5/
Hewlett-Packard Limited Cain Road, Bracknell, registered
no:
registered office: Berks RG12 1HN 690597
England
On Tue, 22 Jul 2008 17:34:24 +0530, Chris Dollin <ch**********@h p.com>
wrote:
>
Doesn't one /want/ (many) realloc calls to be quietly expansive?
That looks slick. Better than calling realloc/malloc(which makes system
calls to underlying OS on most of the platforms; QUITE expansive)
-- Posted on news://freenews.netfront.net - Complaints to ne**@netfront.n et --
On Tue, 22 Jul 2008 17:34:24 +0530, Chris Dollin <ch**********@h p.com>
wrote:
rahul wrote:
>That looks slick. Better than calling realloc/malloc(which makes system calls to underlying OS on most of the platforms; quiet expansive)
Doesn't one /want/ (many) realloc calls to be quietly expansive?
QUITE EXPENSIVE (before you correct my other misspelling)
-- Posted on news://freenews.netfront.net - Complaints to ne**@netfront.n et -- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: robix |
last post by:
Hi again. I'm now asking your help because of a smal problem i'm getting
with my multiplication matrix code.
I'll try to give you as many details as possible.
My matrix structure:
typedef struct {
int col; /* number of colowns */
int lin; /* number of lines*/
|
by: Jack Middleton |
last post by:
Hi!
I'm lookin for a faster permutation algorithm for matrices. I know that
it can be done with multiplying a matrix with a permutation matrix. It
just seems a waste to iterate through all those zeroes. Is there an
algorithm for matrixes that is optimized just for permutations? The
matrices that I use are fairly small (around 6*6) and I only use
positive integers as elements.
Thanks for help,
|
by: Duncan M Gunn |
last post by:
Hi,
I need to store the following matrix of values:
T U V
A 2 1 1
B 2 - -
C - - 2
Where (-) is an empty cell.
|
by: L. |
last post by:
Hello,
I need to generate random Matrices (say of size 5*5), each with an
average of X (say X=0.5), but with different values’ range. One
matrix should have values in the range of 0-1, while the second one’s
values should have a low variance and lie in the range of (X-1) –
(X+1). The matrices represent a visual scene and the values represent the
Gray-level intensities.
I'm using Matlab 6.5 but currently looking for any...
|
by: deLenn |
last post by:
Hi,
Does scipy have an equivalent to Matlab's 'find' function, to list the
indices of all nonzero elements in a sparse matrix?
Cheers.
| |
by: DarrenWeber |
last post by:
Below is a module (matrix.py) with a class to implement some basic
matrix operations on a 2D list. Some things puzzle me about the best
way to do this (please don't refer to scipy, numpy and numeric because
this is a personal programming exercise for me in creating an
operational class in pure python for some *basic* matrix operations).
1. Please take a look at the __init__ function and comment on the
initialization of the list data...
|
by: DarrenWeber |
last post by:
# Copyright (C) 2007 Darren Lee Weber
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY...
|
by: LolaT |
last post by:
I am making a program that deals with matrices in Java.
I keep getting an error and I don't know how to fix it
my code so far is
import java.io.*;
import java.util.*;
import java.util.Scanner;
|
by: Babak |
last post by:
Hi,
I've developed a C program which contains a large number of vectors
and matrices operations. Throughout my code, I used the template from
the Numerical Recipes book to define vectors and matrices and access
their elements. For example, to define a vector I used the function:
my_vector=vector(0,n-1);
Which actually allocate the memory as follows:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |